File tree Expand file tree Collapse file tree 1 file changed +48
-2
lines changed
packages/md-compiler/src/compiler Expand file tree Collapse file tree 1 file changed +48
-2
lines changed Original file line number Diff line number Diff line change @@ -25,9 +25,55 @@ describe('parseMdx property tests', () => {
2525 fc . stringMatching ( / ^ [ A - Z a - z 0 - 9 , . ! ? ] { 1 , 60 } $ / )
2626 )
2727
28- /** MDX expression strings like `{variable}` or `{1 + 2}` */
28+ /** JS reserved words that would make acorn throw when used in MDX expressions like {do} */
29+ const jsReservedInExpression = new Set ( [
30+ 'do' ,
31+ 'if' ,
32+ 'in' ,
33+ 'for' ,
34+ 'let' ,
35+ 'new' ,
36+ 'try' ,
37+ 'var' ,
38+ 'case' ,
39+ 'else' ,
40+ 'enum' ,
41+ 'null' ,
42+ 'break' ,
43+ 'catch' ,
44+ 'class' ,
45+ 'const' ,
46+ 'super' ,
47+ 'throw' ,
48+ 'while' ,
49+ 'with' ,
50+ 'yield' ,
51+ 'delete' ,
52+ 'export' ,
53+ 'import' ,
54+ 'return' ,
55+ 'typeof' ,
56+ 'default' ,
57+ 'finally' ,
58+ 'extends' ,
59+ 'switch' ,
60+ 'function' ,
61+ 'continue' ,
62+ 'debugger' ,
63+ 'interface' ,
64+ 'package' ,
65+ 'private' ,
66+ 'protected' ,
67+ 'public' ,
68+ 'static' ,
69+ 'implements' ,
70+ 'instanceof'
71+ ] )
72+ /** MDX expression strings like `{variable}` or `{1 + 2}` (exclude reserved words so acorn does not throw) */
2973 const mdxExpressionArb = fc . oneof (
30- fc . stringMatching ( / ^ [ a - z ] [ a - z A - Z 0 - 9 ] { 0 , 9 } $ / ) . map ( v => `{${ v } }` ) ,
74+ fc . stringMatching ( / ^ [ a - z ] [ a - z A - Z 0 - 9 ] { 0 , 9 } $ / )
75+ . filter ( v => ! jsReservedInExpression . has ( v ) )
76+ . map ( v => `{${ v } }` ) ,
3177 fc . integer ( { min : - 100 , max : 100 } ) . map ( n => `{${ n } }` ) ,
3278 fc . constant ( '{true}' ) ,
3379 fc . constant ( '{false}' ) ,
You can’t perform that action at this time.
0 commit comments