@vue/language-core
Advanced tools
@@ -213,3 +213,3 @@ "use strict"; | ||
| }); | ||
| if (ctx.scopes.some(scope => scope.has(propVariableName))) { | ||
| if ((0, interpolation_1.shouldIdentifierSkipped)(ctx, propVariableName)) { | ||
| yield* codes; | ||
@@ -216,0 +216,0 @@ } |
@@ -7,1 +7,2 @@ import type { Code, IRBlock, VueCodeInformation } from '../../types'; | ||
| }, ctx: TemplateCodegenContext, block: IRBlock, data: VueCodeInformation, code: string, start: number, prefix?: string, suffix?: string): Generator<Code>; | ||
| export declare function shouldIdentifierSkipped(ctx: TemplateCodegenContext, text: string): boolean; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.generateInterpolation = generateInterpolation; | ||
| exports.shouldIdentifierSkipped = shouldIdentifierSkipped; | ||
| const shared_1 = require("@vue/shared"); | ||
@@ -10,56 +11,40 @@ const collectBindings_1 = require("../../utils/collectBindings"); | ||
| const utils_1 = require("../utils"); | ||
| const boundary_1 = require("../utils/boundary"); | ||
| // https://github.com/vuejs/core/blob/fb0c3ca519f1fccf52049cd6b8db3a67a669afe9/packages/compiler-core/src/transforms/transformExpression.ts#L47 | ||
| const isLiteralWhitelisted = /*@__PURE__*/ (0, shared_1.makeMap)('true,false,null,this'); | ||
| function* generateInterpolation({ typescript, setupRefs }, ctx, block, data, code, start, prefix = '', suffix = '') { | ||
| for (const segment of forEachInterpolationSegment(typescript, setupRefs, ctx, block, code, start, prefix, suffix)) { | ||
| if (typeof segment === 'string') { | ||
| yield segment; | ||
| continue; | ||
| } | ||
| let [section, offset, type] = segment; | ||
| offset -= prefix.length; | ||
| let addSuffix = ''; | ||
| const overLength = offset + section.length - code.length; | ||
| if (overLength > 0) { | ||
| addSuffix = section.slice(section.length - overLength); | ||
| section = section.slice(0, -overLength); | ||
| } | ||
| if (offset < 0) { | ||
| yield section.slice(0, -offset); | ||
| section = section.slice(-offset); | ||
| offset = 0; | ||
| } | ||
| const shouldSkip = section.length === 0 && type === 'startEnd'; | ||
| if (!shouldSkip) { | ||
| if (prefix) { | ||
| yield prefix; | ||
| } | ||
| let prevEnd = 0; | ||
| for (const [name, offset, isShorthand] of forEachIdentifiers(typescript, ctx, block, code, prefix, suffix)) { | ||
| if (isShorthand) { | ||
| yield [ | ||
| section, | ||
| code.slice(prevEnd, offset + name.length), | ||
| block.name, | ||
| start + offset, | ||
| type === 'errorMappingOnly' | ||
| ? codeFeatures_1.codeFeatures.verification | ||
| : type === 'shorthand' | ||
| ? { ...data, __shorthandExpression: 'js' } | ||
| : data, | ||
| start + prevEnd, | ||
| data, | ||
| ]; | ||
| } | ||
| yield addSuffix; | ||
| } | ||
| } | ||
| function* forEachInterpolationSegment(ts, setupRefs, ctx, block, originalCode, start, prefix, suffix) { | ||
| const code = prefix + originalCode + suffix; | ||
| let prevEnd = 0; | ||
| for (const [name, offset, isShorthand] of forEachIdentifiers(ts, ctx, block, originalCode, code, prefix)) { | ||
| if (isShorthand) { | ||
| yield [code.slice(prevEnd, offset + name.length), prevEnd]; | ||
| yield `: `; | ||
| } | ||
| else { | ||
| yield [code.slice(prevEnd, offset), prevEnd, prevEnd > 0 ? undefined : 'startEnd']; | ||
| else if (prevEnd < offset) { | ||
| yield [ | ||
| code.slice(prevEnd, offset), | ||
| block.name, | ||
| start + prevEnd, | ||
| data, | ||
| ]; | ||
| } | ||
| if (setupRefs.has(name)) { | ||
| yield [name, offset]; | ||
| yield [ | ||
| name, | ||
| block.name, | ||
| start + offset, | ||
| data, | ||
| ]; | ||
| yield `.value`; | ||
| } | ||
| else { | ||
| yield ['', offset, 'errorMappingOnly']; // #1205, #1264 | ||
| // #1205, #1264 | ||
| const token = yield* (0, boundary_1.startBoundary)(block.name, start + offset, codeFeatures_1.codeFeatures.verification); | ||
| if (ctx.dollarVars.has(name)) { | ||
@@ -69,7 +54,15 @@ yield names_1.names.dollars; | ||
| else { | ||
| ctx.recordComponentAccess(block.name, name, start - prefix.length + offset); | ||
| ctx.recordComponentAccess(block.name, name, start + offset); | ||
| yield names_1.names.ctx; | ||
| } | ||
| yield `.`; | ||
| yield [name, offset, isShorthand ? 'shorthand' : undefined]; | ||
| yield [ | ||
| name, | ||
| block.name, | ||
| start + offset, | ||
| isShorthand | ||
| ? { ...data, __shorthandExpression: 'js' } | ||
| : data, | ||
| ]; | ||
| yield (0, boundary_1.endBoundary)(token, start + offset + name.length); | ||
| } | ||
@@ -79,12 +72,20 @@ prevEnd = offset + name.length; | ||
| if (prevEnd < code.length) { | ||
| yield [code.slice(prevEnd), prevEnd, 'startEnd']; | ||
| yield [ | ||
| code.slice(prevEnd), | ||
| block.name, | ||
| start + prevEnd, | ||
| data, | ||
| ]; | ||
| } | ||
| if (suffix) { | ||
| yield suffix; | ||
| } | ||
| } | ||
| function* forEachIdentifiers(ts, ctx, block, originalCode, code, prefix) { | ||
| if (utils_1.identifierRegex.test(originalCode) && !shouldIdentifierSkipped(ctx, originalCode)) { | ||
| yield [originalCode, prefix.length, false]; | ||
| function* forEachIdentifiers(ts, ctx, block, code, prefix, suffix) { | ||
| if (utils_1.identifierRegex.test(code) && !shouldIdentifierSkipped(ctx, code)) { | ||
| yield [code, 0, false]; | ||
| return; | ||
| } | ||
| const endScope = ctx.startScope(); | ||
| const ast = (0, utils_1.getTypeScriptAST)(ts, block, code); | ||
| const ast = (0, utils_1.getTypeScriptAST)(ts, block, prefix + code + suffix); | ||
| for (const [id, isShorthand] of forEachDeclarations(ts, ast, ast, ctx)) { | ||
@@ -95,3 +96,3 @@ const text = (0, shared_2.getNodeText)(ts, id, ast); | ||
| } | ||
| yield [text, (0, shared_2.getStartEnd)(ts, id, ast).start, isShorthand]; | ||
| yield [text, (0, shared_2.getStartEnd)(ts, id, ast).start - prefix.length, isShorthand]; | ||
| } | ||
@@ -98,0 +99,0 @@ endScope(); |
+2
-2
| { | ||
| "name": "@vue/language-core", | ||
| "version": "3.3.1", | ||
| "version": "3.3.2", | ||
| "license": "MIT", | ||
@@ -37,3 +37,3 @@ "files": [ | ||
| }, | ||
| "gitHead": "9109bf31282c3d92ca0dd1825b0872a59b572b84" | ||
| "gitHead": "7a00047bb6d133bf26fa6e916e856fdca40b3c49" | ||
| } |
@@ -112,3 +112,3 @@ declare global { | ||
| function __VLS_vFor<T>(source: T): T extends number ? [number, number][] | ||
| function __VLS_vFor<const T>(source: T): T extends number ? [number, number][] | ||
| : T extends string ? [string, number][] | ||
@@ -115,0 +115,0 @@ : T extends readonly (infer U)[] ? [U, number][] |
8989
0.02%391559
-0.09%