From: 三咲智子 Kevin Deng Date: Fri, 1 Dec 2023 16:49:13 +0000 (+0800) Subject: fix: identifier source map X-Git-Tag: v3.6.0-alpha.1~16^2~766 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=89cefda3add3004e5902a6a570efc92a8ee39c32;p=thirdparty%2Fvuejs%2Fcore.git fix: identifier source map --- diff --git a/packages/compiler-vapor/src/generate.ts b/packages/compiler-vapor/src/generate.ts index 1e12ffee68..f1cd4e19f2 100644 --- a/packages/compiler-vapor/src/generate.ts +++ b/packages/compiler-vapor/src/generate.ts @@ -2,11 +2,13 @@ import { type CodegenOptions, type CodegenResult, type Position, + type SourceLocation, NewlineType, advancePositionWithMutation, locStub, NodeTypes, BindingTypes, + isSimpleIdentifier, } from '@vue/compiler-dom' import { type IRDynamicChildren, @@ -14,7 +16,6 @@ import { IRNodeTypes, OperationNode, VaporHelper, - BaseIRNode, IRExpression, } from './ir' import { SourceMapGenerator } from 'source-map-js' @@ -36,12 +37,14 @@ export interface CodegenContext extends Required { push( code: string, newlineIndex?: number, - node?: Pick, + loc?: SourceLocation, + name?: string, ): void pushWithNewline( code: string, newlineIndex?: number, - node?: Pick, + loc?: SourceLocation, + name?: string, ): void indent(): void deindent(): void @@ -106,20 +109,11 @@ function createCodegenContext( vaporHelpers.add(name) return `_${name}` }, - push(code, newlineIndex = NewlineType.None, node) { + push(code, newlineIndex = NewlineType.None, loc, name) { context.code += code if (!__BROWSER__ && context.map) { - if (node) { - // TODO - let name - // if (node.type === NodeTypes.SIMPLE_EXPRESSION && !node.isStatic) { - // const content = node.content.replace(/^_ctx\./, '') - // if (content !== node.content && isSimpleIdentifier(content)) { - // name = content - // } - // } - addMapping(node.loc.start, name) - } + if (loc) addMapping(loc.start, name) + if (newlineIndex === NewlineType.Unknown) { // multiple newlines, full iteration advancePositionWithMutation(context, code) @@ -155,8 +149,8 @@ function createCodegenContext( context.column = code.length - newlineIndex } } - if (node && node.loc !== locStub) { - addMapping(node.loc.end) + if (loc && loc !== locStub) { + addMapping(loc.end) } } }, @@ -427,7 +421,8 @@ function genExpression( // TODO NodeTypes.COMPOUND_EXPRESSION if (exp.type === NodeTypes.COMPOUND_EXPRESSION) return - let content = exp.content + let { content } = exp + let name: string | undefined if (exp.isStatic) { content = JSON.stringify(content) @@ -441,9 +436,10 @@ function genExpression( break } if (prefixIdentifiers && !inline) { + if (isSimpleIdentifier(content)) name = content content = `_ctx.${content}` } } - push(content, NewlineType.None, exp) + push(content, NewlineType.None, exp.loc, name) }