refactor(compiler): better constant hoist/stringify checks

This commit is contained in:
Evan You
2020-11-20 19:26:07 -05:00
parent acba86ef45
commit 90bdf59f4c
22 changed files with 291 additions and 204 deletions

View File

@@ -1,5 +1,6 @@
import path from 'path'
import {
ConstantTypes,
createSimpleExpression,
ExpressionNode,
NodeTransform,
@@ -159,19 +160,26 @@ function getImportsExpressionExp(
return existing.exp as ExpressionNode
}
const name = `_imports_${importsArray.length}`
const exp = createSimpleExpression(name, false, loc, true)
exp.isRuntimeConstant = true
const exp = createSimpleExpression(
name,
false,
loc,
ConstantTypes.CAN_HOIST
)
context.imports.add({ exp, path })
if (hash && path) {
const ret = context.hoist(
createSimpleExpression(`${name} + '${hash}'`, false, loc, true)
return context.hoist(
createSimpleExpression(
`${name} + '${hash}'`,
false,
loc,
ConstantTypes.CAN_HOIST
)
)
ret.isRuntimeConstant = true
return ret
} else {
return exp
}
} else {
return createSimpleExpression(`''`, false, loc, true)
return createSimpleExpression(`''`, false, loc, ConstantTypes.CAN_HOIST)
}
}