diff --git a/.changeset/twenty-rice-fix.md b/.changeset/twenty-rice-fix.md new file mode 100644 index 000000000..82923529e --- /dev/null +++ b/.changeset/twenty-rice-fix.md @@ -0,0 +1,6 @@ +--- +'@vue-macros/hoist-static': minor +'@vue-macros/common': patch +--- + +don't hoist regexp diff --git a/packages/common/src/ast.ts b/packages/common/src/ast.ts index f8c1b85ee..78c3db4cc 100644 --- a/packages/common/src/ast.ts +++ b/packages/common/src/ast.ts @@ -73,12 +73,16 @@ export function checkInvalidScopeReference( export function isStaticExpression( node: Node, options: Partial< - Record<'object' | 'fn' | 'objectMethod' | 'array' | 'unary', boolean> & { + Record< + 'object' | 'fn' | 'objectMethod' | 'array' | 'unary' | 'regex', + boolean + > & { magicComment?: string } > = {} ): boolean { - const { magicComment, fn, object, objectMethod, array, unary } = options + const { magicComment, fn, object, objectMethod, array, unary, regex } = + options // magic comment if ( @@ -148,7 +152,11 @@ export function isStaticExpression( case 'TSNonNullExpression': // 1! case 'TSAsExpression': // 1 as number case 'TSTypeAssertion': // (2) + case 'TSSatisfiesExpression': // 1 satisfies number return isStaticExpression(node.expression, options) + + case 'RegExpLiteral': + return !!regex } if (isLiteralType(node)) return true diff --git a/packages/hoist-static/tests/__snapshots__/fixtures.test.ts.snap b/packages/hoist-static/tests/__snapshots__/fixtures.test.ts.snap index d64008cd5..3e466d2cd 100644 --- a/packages/hoist-static/tests/__snapshots__/fixtures.test.ts.snap +++ b/packages/hoist-static/tests/__snapshots__/fixtures.test.ts.snap @@ -23,6 +23,7 @@ const d = 1 || 2 const e = !1 const f = 1 ? 2 : 3 const g = 1 as number +const h = 2