Skip to content

Commit 09d3100

Browse files
TrueNinecursoragent
andcommitted
fix(md-compiler): exclude JS reserved words from parseMdx property test arb
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent defca23 commit 09d3100

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

packages/md-compiler/src/compiler/parser.property.test.ts

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,55 @@ describe('parseMdx property tests', () => {
2525
fc.stringMatching(/^[A-Za-z0-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-zA-Z0-9]{0,9}$/).map(v => `{${v}}`),
74+
fc.stringMatching(/^[a-z][a-zA-Z0-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}'),

0 commit comments

Comments
 (0)