components: Set<string>
directives: Set<string>
hoists: (JSChildNode | null)[]
- imports: Set<ImportItem>
+ imports: ImportItem[]
temps: number
cached: number
identifiers: { [name: string]: number | undefined }
components: new Set(),
directives: new Set(),
hoists: [],
- imports: new Set(),
+ imports: [],
constantCache: new Map(),
temps: 0,
cached: 0,
root.helpers = [...context.helpers]
root.components = [...context.components]
root.directives = [...context.directives]
- root.imports = [...context.imports]
+ root.imports = context.imports
root.hoists = context.hoists
root.temps = context.temps
root.cached = context.cached
context: TransformContext
): ExpressionNode {
if (path) {
- const importsArray = Array.from(context.imports)
- const existing = importsArray.find(i => i.path === path)
+ const existing = context.imports.find(i => i.path === path)
if (existing) {
return existing.exp as ExpressionNode
}
- const name = `_imports_${importsArray.length}`
+ const name = `_imports_${context.imports.length}`
const exp = createSimpleExpression(
name,
false,
loc,
ConstantTypes.CAN_HOIST
)
- context.imports.add({ exp, path })
+ context.imports.push({ exp, path })
if (hash && path) {
return context.hoist(
createSimpleExpression(
const { path } = parseUrl(url)
let exp: SimpleExpressionNode
if (path) {
- const importsArray = Array.from(context.imports)
- const existingImportsIndex = importsArray.findIndex(
+ const existingImportsIndex = context.imports.findIndex(
i => i.path === path
)
if (existingImportsIndex > -1) {
)
} else {
exp = createSimpleExpression(
- `_imports_${importsArray.length}`,
+ `_imports_${context.imports.length}`,
false,
attr.loc,
ConstantTypes.CAN_HOIST
)
- context.imports.add({ exp, path })
+ context.imports.push({ exp, path })
}
compoundExpression.children.push(exp)
}
childContext.identifiers = { ...parentContext.identifiers }
// traverse
traverseNode(childRoot, childContext)
- // merge helpers/components/directives/imports into parent context
- ;(['helpers', 'components', 'directives', 'imports'] as const).forEach(
- key => {
- childContext[key].forEach((value: any) => {
- ;(parentContext[key] as any).add(value)
- })
- }
- )
+ // merge helpers/components/directives into parent context
+ ;(['helpers', 'components', 'directives'] as const).forEach(key => {
+ childContext[key].forEach((value: any) => {
+ ;(parentContext[key] as any).add(value)
+ })
+ })
+ // imports/hoists are not merged because:
+ // - imports are only used for asset urls and should be consistent between
+ // node/client branches
+ // - hoists are not enabled for the client branch here
}
function clone(v: any): any {