Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a bug in EuiCodeBlock docs where import statement example was raised up and evaluated. #6595

Merged
merged 4 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src-docs/src/components/guide_section/_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,12 @@ export const renderJsSourceCode = (code) => {
const remainingImports = [];

renderedCode = renderedCode.replace(
// (?<!(`[\s\S]*)) - negative lookbehind ensuring that import statements aren't part of a template literal
// (\/\/.+\n)? - optional preceding comments that must be above specific imports, e.g. // @ts-ignore
// import - import + whitespace
// ([^]+?) - capture any characters (including newlines)
// from ('[A-Za-z0-9 -_.@/]*';) - ` from 'someLibrary';` - alphanumeric and certain special characters only
/(\/\/.+\n)?import ([^]+?) from ('[A-Za-z0-9 -_.@/]*';)/g,
/(?<!(`[\s\S]*))(\/\/.+\n)?import ([^]+?) from ('[A-Za-z0-9 -_.@/]*';)/g,
(match) => {
remainingImports.push(match);
return '';
Expand Down
25 changes: 25 additions & 0 deletions src-docs/src/components/guide_section/_utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,5 +314,30 @@ describe('renderJsSourceCode', () => {
export default () => 'Hello world!';`)
);
});

it('does not handle import statements within template literal backticks', () => {
expect(
renderJsSourceCode({
default: dedent(`
import React from 'react';

import { v4 } from '@uuid/v4';

const jsCode = \`/* I'm an example of JS */
import React from 'react';\`;

export default () => 'Hello world!';`),
})
).toEqual(
dedent(`
import React from 'react';
import { v4 } from '@uuid/v4';

const jsCode = \`/* I'm an example of JS */
import React from 'react';\`;

export default () => 'Hello world!';`)
);
});
});
});