const nil = null
const bigint = 100n
const template = \`str\`
- const regex = /.*/g
`.trim()
const { content, bindings } = compile(`
<script setup>
boolean: BindingTypes.LITERAL_CONST,
nil: BindingTypes.LITERAL_CONST,
bigint: BindingTypes.LITERAL_CONST,
- template: BindingTypes.LITERAL_CONST,
- regex: BindingTypes.LITERAL_CONST
+ template: BindingTypes.LITERAL_CONST
})
assertCode(content)
})
const code = `
let KEY1 = 'default value'
var KEY2 = 123
+ const regex = /.*/g
+ const undef = undefined
`.trim()
const { content, bindings } = compile(`
<script setup>
`)
expect(bindings).toStrictEqual({
KEY1: BindingTypes.SETUP_LET,
- KEY2: BindingTypes.SETUP_LET
+ KEY2: BindingTypes.SETUP_LET,
+ regex: BindingTypes.SETUP_CONST,
+ undef: BindingTypes.SETUP_MAYBE_REF
})
expect(content).toMatch(`setup(__props) {\n\n ${code}`)
assertCode(content)
}
function isStaticNode(node: Node): boolean {
+ node = unwrapTSNode(node)
+
switch (node.type) {
case 'UnaryExpression': // void 0, !true
return isStaticNode(node.argument)
return node.expressions.every(expr => isStaticNode(expr))
case 'ParenthesizedExpression': // (1)
- case 'TSNonNullExpression': // 1!
- case 'TSAsExpression': // 1 as number
- case 'TSTypeAssertion': // (<number>2)
return isStaticNode(node.expression)
- default:
- if (isLiteralNode(node)) {
- return true
- }
- return false
+ case 'StringLiteral':
+ case 'NumericLiteral':
+ case 'BooleanLiteral':
+ case 'NullLiteral':
+ case 'BigIntLiteral':
+ return true
}
+ return false
}