@vue/language-core
Advanced tools
Comparing version 2.0.13 to 2.0.14
@@ -1,2 +0,2 @@ | ||
export * from './lib/generators/template'; | ||
export * from './lib/codegen/template'; | ||
export * from './lib/languageModule'; | ||
@@ -3,0 +3,0 @@ export * from './lib/parsers/scriptSetupRanges'; |
@@ -18,3 +18,3 @@ "use strict"; | ||
exports.tsCodegen = exports.scriptRanges = void 0; | ||
__exportStar(require("./lib/generators/template"), exports); | ||
__exportStar(require("./lib/codegen/template"), exports); | ||
__exportStar(require("./lib/languageModule"), exports); | ||
@@ -21,0 +21,0 @@ __exportStar(require("./lib/parsers/scriptSetupRanges"), exports); |
import { type LanguagePlugin } from '@volar/language-core'; | ||
import type * as ts from 'typescript'; | ||
import type { VueCompilerOptions, VueLanguagePlugin } from './types'; | ||
import { VueGeneratedCode } from './virtualFile/vueFile'; | ||
interface _Plugin extends LanguagePlugin<VueGeneratedCode> { | ||
import { VueVirtualCode } from './virtualFile/vueFile'; | ||
interface _Plugin extends LanguagePlugin<VueVirtualCode> { | ||
getCanonicalFileName: (fileName: string) => string; | ||
pluginContext: Parameters<VueLanguagePlugin>[0]; | ||
} | ||
export declare function createVueLanguagePlugin(ts: typeof import('typescript'), getFileName: (fileId: string) => string, useCaseSensitiveFileNames: boolean, getProjectVersion: () => string, getScriptFileNames: () => string[] | Set<string>, compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions, codegenStack?: boolean): _Plugin; | ||
export declare function createVueLanguagePlugin(ts: typeof import('typescript'), getFileName: (fileId: string) => string, useCaseSensitiveFileNames: boolean, getProjectVersion: () => string, getScriptFileNames: () => string[] | Set<string>, compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions): _Plugin; | ||
export {}; |
@@ -38,3 +38,3 @@ "use strict"; | ||
} | ||
function createVueLanguagePlugin(ts, getFileName, useCaseSensitiveFileNames, getProjectVersion, getScriptFileNames, compilerOptions, vueCompilerOptions, codegenStack = false) { | ||
function createVueLanguagePlugin(ts, getFileName, useCaseSensitiveFileNames, getProjectVersion, getScriptFileNames, compilerOptions, vueCompilerOptions) { | ||
const allowLanguageIds = new Set(['vue']); | ||
@@ -53,3 +53,2 @@ const pluginContext = { | ||
vueCompilerOptions, | ||
codegenStack, | ||
globalTypesHolder: undefined, | ||
@@ -90,3 +89,3 @@ }; | ||
else { | ||
const code = new vueFile_1.VueGeneratedCode(fileName, languageId, snapshot, vueCompilerOptions, plugins, ts, codegenStack); | ||
const code = new vueFile_1.VueVirtualCode(fileName, languageId, snapshot, vueCompilerOptions, plugins, ts); | ||
fileRegistry.set(fileId, code); | ||
@@ -93,0 +92,0 @@ return code; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const utils_1 = require("../generators/utils"); | ||
const shared_1 = require("./shared"); | ||
const plugin = () => { | ||
@@ -21,3 +21,3 @@ return { | ||
0, | ||
(0, utils_1.enableAllFeatures)({}), | ||
shared_1.allCodeFeatures, | ||
]); | ||
@@ -24,0 +24,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const utils_1 = require("../generators/utils"); | ||
const plugin = () => { | ||
@@ -26,6 +25,6 @@ return { | ||
0, | ||
(0, utils_1.disableAllFeatures)({ | ||
{ | ||
structure: true, | ||
format: true, | ||
}), | ||
}, | ||
]); | ||
@@ -32,0 +31,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const utils_1 = require("../generators/utils"); | ||
const shared_1 = require("./shared"); | ||
const plugin = () => { | ||
@@ -37,3 +37,3 @@ return { | ||
cssVar.offset, | ||
(0, utils_1.enableAllFeatures)({}), | ||
shared_1.allCodeFeatures, | ||
], ');\n'); | ||
@@ -47,3 +47,3 @@ } | ||
0, | ||
(0, utils_1.enableAllFeatures)({}), | ||
shared_1.allCodeFeatures, | ||
]); | ||
@@ -50,0 +50,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const utils_1 = require("../generators/utils"); | ||
const shared_1 = require("./shared"); | ||
const plugin = () => { | ||
@@ -22,3 +22,3 @@ return { | ||
0, | ||
(0, utils_1.enableAllFeatures)({}), | ||
shared_1.allCodeFeatures, | ||
]); | ||
@@ -25,0 +25,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const inlineCss_1 = require("../generators/inlineCss"); | ||
const CompilerDOM = require("@vue/compiler-dom"); | ||
const template_1 = require("../codegen/template"); | ||
const shared_1 = require("./shared"); | ||
const codeFeatures = { | ||
...shared_1.allCodeFeatures, | ||
format: false, | ||
structure: false, | ||
}; | ||
const plugin = () => { | ||
@@ -18,3 +25,3 @@ return { | ||
embeddedFile.parentCodeId = 'template'; | ||
embeddedFile.content.push(...(0, inlineCss_1.generate)(sfc.template.ast)); | ||
embeddedFile.content.push(...generate(sfc.template.ast)); | ||
}, | ||
@@ -24,2 +31,27 @@ }; | ||
exports.default = plugin; | ||
function* generate(templateAst) { | ||
for (const node of (0, template_1.forEachElementNode)(templateAst)) { | ||
for (const prop of node.props) { | ||
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE | ||
&& prop.name === 'bind' | ||
&& prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION | ||
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION | ||
&& prop.arg.content === 'style' | ||
&& prop.exp.constType === CompilerDOM.ConstantTypes.CAN_STRINGIFY) { | ||
const endCrt = prop.arg.loc.source[prop.arg.loc.source.length - 1]; // " | ' | ||
const start = prop.arg.loc.source.indexOf(endCrt) + 1; | ||
const end = prop.arg.loc.source.lastIndexOf(endCrt); | ||
const content = prop.arg.loc.source.substring(start, end); | ||
yield `x { `; | ||
yield [ | ||
content, | ||
'template', | ||
prop.arg.loc.start.offset + start, | ||
codeFeatures, | ||
]; | ||
yield ` }\n`; | ||
} | ||
} | ||
} | ||
} | ||
//# sourceMappingURL=vue-template-inline-css.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const template_1 = require("../generators/template"); | ||
const utils_1 = require("../generators/utils"); | ||
const common_1 = require("../codegen/common"); | ||
const elementEvents_1 = require("../codegen/template/elementEvents"); | ||
const templateChild_1 = require("../codegen/template/templateChild"); | ||
const vFor_1 = require("../codegen/template/vFor"); | ||
const CompilerDOM = require("@vue/compiler-dom"); | ||
const codeFeatures = (0, utils_1.disableAllFeatures)({ | ||
const codeFeatures = { | ||
format: true, | ||
// autoInserts: true, // TODO: support vue-autoinsert-parentheses | ||
}); | ||
}; | ||
const formatBrackets = { | ||
@@ -76,4 +78,4 @@ normal: ['`${', '}`;'], | ||
if (prop.name === 'on') { | ||
const ast = (0, template_1.createTsAst)(ctx.modules.typescript, prop.exp, prop.exp.content); | ||
addFormatCodes(prop.exp.content, prop.exp.loc.start.offset, (0, template_1.isCompoundExpression)(ctx.modules.typescript, ast) | ||
const ast = (0, common_1.createTsAst)(ctx.modules.typescript, prop.exp, prop.exp.content); | ||
addFormatCodes(prop.exp.content, prop.exp.loc.start.offset, (0, elementEvents_1.isCompoundExpression)(ctx.modules.typescript, ast) | ||
? formatBrackets.event | ||
@@ -103,3 +105,3 @@ : formatBrackets.normal); | ||
else if (node.type === CompilerDOM.NodeTypes.FOR) { | ||
const { leftExpressionRange, leftExpressionText } = (0, template_1.parseVForNode)(node); | ||
const { leftExpressionRange, leftExpressionText } = (0, vFor_1.parseVForNode)(node); | ||
const { source } = node.parseResult; | ||
@@ -129,3 +131,3 @@ if (leftExpressionRange && leftExpressionText && source.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) { | ||
// {{ ... }} | ||
const [content, start] = (0, template_1.parseInterpolationNode)(node, templateContent); | ||
const [content, start] = (0, templateChild_1.parseInterpolationNode)(node, templateContent); | ||
const lines = content.split('\n'); | ||
@@ -132,0 +134,0 @@ addFormatCodes(content, start, lines.length <= 1 ? formatBrackets.curly : [ |
@@ -1,2 +0,2 @@ | ||
import { Mapping, StackNode } from '@volar/language-core'; | ||
import type { Mapping } from '@volar/language-core'; | ||
import type { Code, Sfc, VueLanguagePlugin } from '../types'; | ||
@@ -65,3 +65,2 @@ export declare const tsCodegen: WeakMap<Sfc, { | ||
codes: Code[]; | ||
codeStacks: StackNode[]; | ||
linkedCodeMappings: Mapping<any>[]; | ||
@@ -71,5 +70,43 @@ }; | ||
codes: Code[]; | ||
codeStacks: string[]; | ||
tagOffsetsMap: Map<string, number[]>; | ||
accessedGlobalVariables: Set<string>; | ||
ctx: { | ||
slots: { | ||
name: string; | ||
loc?: number | undefined; | ||
tagRange: [number, number]; | ||
varName: string; | ||
nodeLoc: any; | ||
}[]; | ||
dynamicSlots: { | ||
expVar: string; | ||
varName: string; | ||
}[]; | ||
codeFeatures: { | ||
all: import("../types").VueCodeInformation; | ||
verification: import("../types").VueCodeInformation; | ||
completion: import("../types").VueCodeInformation; | ||
additionalCompletion: import("../types").VueCodeInformation; | ||
navigation: import("../types").VueCodeInformation; | ||
navigationAndCompletion: import("../types").VueCodeInformation; | ||
withoutHighlight: import("../types").VueCodeInformation; | ||
withoutHighlightAndCompletion: import("../types").VueCodeInformation; | ||
withoutHighlightAndCompletionAndNavigation: import("../types").VueCodeInformation; | ||
}; | ||
accessGlobalVariables: Map<string, Set<number>>; | ||
hasSlotElements: Set<import("@vue/compiler-dom").ElementNode>; | ||
blockConditions: string[]; | ||
usedComponentCtxVars: Set<string>; | ||
scopedClasses: { | ||
className: string; | ||
offset: number; | ||
}[]; | ||
accessGlobalVariable(name: string, offset?: number | undefined): void; | ||
hasLocalVariable: (name: string) => boolean; | ||
addLocalVariable: (name: string) => void; | ||
removeLocalVariable: (name: string) => void; | ||
getInternalVariable: () => string; | ||
ignoreError: () => Generator<Code, any, unknown>; | ||
expectError: (prevNode: import("@vue/compiler-dom").CommentNode) => Generator<Code, any, unknown>; | ||
resetDirectiveComments: (endStr: string) => Generator<Code, any, unknown>; | ||
generateAutoImportCompletion: () => Generator<Code, any, unknown>; | ||
}; | ||
hasSlot: boolean; | ||
@@ -76,0 +113,0 @@ } | undefined; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.tsCodegen = void 0; | ||
const language_core_1 = require("@volar/language-core"); | ||
const computeds_1 = require("computeds"); | ||
const script_1 = require("../generators/script"); | ||
const template_1 = require("../generators/template"); | ||
const path = require("path-browserify"); | ||
const script_1 = require("../codegen/script"); | ||
const template_1 = require("../codegen/template"); | ||
const scriptRanges_1 = require("../parsers/scriptRanges"); | ||
@@ -31,5 +31,4 @@ const scriptSetupRanges_1 = require("../parsers/scriptSetupRanges"); | ||
if (tsx) { | ||
const [content, contentStacks] = ctx.codegenStack ? (0, language_core_1.track)([...tsx.codes], [...tsx.codeStacks]) : [[...tsx.codes], [...tsx.codeStacks]]; | ||
const content = [...tsx.codes]; | ||
embeddedFile.content = content; | ||
embeddedFile.contentStacks = contentStacks; | ||
embeddedFile.linkedCodeMappings = [...tsx.linkedCodeMappings]; | ||
@@ -87,12 +86,18 @@ } | ||
} | ||
const tsCodes = []; | ||
const tsCodegenStacks = []; | ||
const codegen = (0, template_1.generate)(ts, ctx.compilerOptions, ctx.vueCompilerOptions, _sfc.template, shouldGenerateScopedClasses(), stylesScopedClasses(), hasScriptSetupSlots(), slotsAssignName(), propsAssignName(), ctx.codegenStack); | ||
const codes = []; | ||
const codegen = (0, template_1.generateTemplate)({ | ||
ts, | ||
compilerOptions: ctx.compilerOptions, | ||
vueCompilerOptions: ctx.vueCompilerOptions, | ||
template: _sfc.template, | ||
shouldGenerateScopedClasses: shouldGenerateScopedClasses(), | ||
stylesScopedClasses: stylesScopedClasses(), | ||
hasDefineSlots: hasDefineSlots(), | ||
slotsAssignName: slotsAssignName(), | ||
propsAssignName: propsAssignName(), | ||
}); | ||
let current = codegen.next(); | ||
while (!current.done) { | ||
const [code, stack] = current.value; | ||
tsCodes.push(code); | ||
if (ctx.codegenStack) { | ||
tsCodegenStacks.push(stack); | ||
} | ||
const code = current.value; | ||
codes.push(code); | ||
current = codegen.next(); | ||
@@ -102,7 +107,6 @@ } | ||
...current.value, | ||
codes: tsCodes, | ||
codeStacks: tsCodegenStacks, | ||
codes: codes, | ||
}; | ||
}); | ||
const hasScriptSetupSlots = (0, computeds_1.computed)(() => !!scriptSetupRanges()?.slots.define); | ||
const hasDefineSlots = (0, computeds_1.computed)(() => !!scriptSetupRanges()?.slots.define); | ||
const slotsAssignName = (0, computeds_1.computed)(() => scriptSetupRanges()?.slots.name); | ||
@@ -112,17 +116,24 @@ const propsAssignName = (0, computeds_1.computed)(() => scriptSetupRanges()?.props.name); | ||
const codes = []; | ||
const codeStacks = []; | ||
const linkedCodeMappings = []; | ||
const _template = generatedTemplate(); | ||
let generatedLength = 0; | ||
for (const [code, stack] of (0, script_1.generate)(ts, fileName, _sfc.script, _sfc.scriptSetup, _sfc.styles, lang(), scriptRanges(), scriptSetupRanges(), _template ? { | ||
tsCodes: _template.codes, | ||
tsCodegenStacks: _template.codeStacks, | ||
accessedGlobalVariables: _template.accessedGlobalVariables, | ||
hasSlot: _template.hasSlot, | ||
tagNames: new Set(_template.tagOffsetsMap.keys()), | ||
} : undefined, ctx.compilerOptions, ctx.vueCompilerOptions, ctx.globalTypesHolder, () => generatedLength, linkedCodeMappings, ctx.codegenStack)) { | ||
for (const code of (0, script_1.generateScript)({ | ||
ts, | ||
fileBaseName: path.basename(fileName), | ||
globalTypes: ctx.globalTypesHolder === fileName, | ||
sfc: _sfc, | ||
lang: lang(), | ||
scriptRanges: scriptRanges(), | ||
scriptSetupRanges: scriptSetupRanges(), | ||
templateCodegen: _template ? { | ||
tsCodes: _template.codes, | ||
ctx: _template.ctx, | ||
hasSlot: _template.hasSlot, | ||
} : undefined, | ||
compilerOptions: ctx.compilerOptions, | ||
vueCompilerOptions: ctx.vueCompilerOptions, | ||
getGeneratedLength: () => generatedLength, | ||
linkedCodeMappings, | ||
})) { | ||
codes.push(code); | ||
if (ctx.codegenStack) { | ||
codeStacks.push({ stack, length: 1 }); | ||
} | ||
generatedLength += typeof code === 'string' | ||
@@ -135,3 +146,2 @@ ? code.length | ||
codes, | ||
codeStacks, | ||
linkedCodeMappings, | ||
@@ -138,0 +148,0 @@ }; |
@@ -22,4 +22,4 @@ import type * as CompilerDOM from '@vue/compiler-dom'; | ||
__combineLastMapping?: boolean; | ||
__combineOffsetMapping?: number; | ||
} | ||
export type CodeAndStack = [code: Code, stack: string]; | ||
export type Code = Segment<VueCodeInformation>; | ||
@@ -33,3 +33,2 @@ export interface VueCompilerOptions { | ||
skipTemplateCodegen: boolean; | ||
nativeTags: string[]; | ||
dataAttributes: string[]; | ||
@@ -61,3 +60,2 @@ htmlAttributes: string[]; | ||
vueCompilerOptions: VueCompilerOptions; | ||
codegenStack: boolean; | ||
globalTypesHolder: string | undefined; | ||
@@ -64,0 +62,0 @@ }) => { |
@@ -154,23 +154,2 @@ "use strict"; | ||
} | ||
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element | ||
const HTML_TAGS = 'html,body,base,head,link,meta,style,title,address,article,aside,footer,' + | ||
'header,hgroup,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,' + | ||
'figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,' + | ||
'data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,' + | ||
'time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,' + | ||
'canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,' + | ||
'th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,' + | ||
'option,output,progress,select,textarea,details,dialog,menu,' + | ||
'summary,template,blockquote,iframe,tfoot'; | ||
// https://developer.mozilla.org/en-US/docs/Web/SVG/Element | ||
const SVG_TAGS = 'svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,' + | ||
'defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer,' + | ||
'feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,' + | ||
'feDistanceLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,' + | ||
'feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,' + | ||
'fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,' + | ||
'foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,' + | ||
'mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,' + | ||
'polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,' + | ||
'text,textPath,title,tspan,unknown,use,view'; | ||
function resolveVueCompilerOptions(vueOptions) { | ||
@@ -187,10 +166,2 @@ const target = vueOptions.target ?? 3.3; | ||
skipTemplateCodegen: vueOptions.skipTemplateCodegen ?? false, | ||
nativeTags: vueOptions.nativeTags ?? [...new Set([ | ||
...HTML_TAGS.split(','), | ||
...SVG_TAGS.split(','), | ||
// fix https://github.com/johnsoncodehk/volar/issues/1340 | ||
'hgroup', | ||
'slot', | ||
'component', | ||
])], | ||
dataAttributes: vueOptions.dataAttributes ?? [], | ||
@@ -197,0 +168,0 @@ htmlAttributes: vueOptions.htmlAttributes ?? ['aria-*'], |
import { VirtualCode } from '@volar/language-core'; | ||
import type { Sfc, VueLanguagePlugin } from '../types'; | ||
export declare function computedFiles(plugins: ReturnType<VueLanguagePlugin>[], fileName: string, sfc: Sfc, codegenStack: boolean): () => VirtualCode[]; | ||
export declare function computedFiles(plugins: ReturnType<VueLanguagePlugin>[], fileName: string, sfc: Sfc): () => VirtualCode[]; |
@@ -7,3 +7,3 @@ "use strict"; | ||
const embeddedFile_1 = require("./embeddedFile"); | ||
function computedFiles(plugins, fileName, sfc, codegenStack) { | ||
function computedFiles(plugins, fileName, sfc) { | ||
const nameToBlock = (0, computeds_1.computed)(() => { | ||
@@ -28,3 +28,3 @@ const blocks = {}; | ||
}); | ||
const pluginsResult = plugins.map(plugin => computedPluginFiles(plugins, plugin, fileName, sfc, nameToBlock, codegenStack)); | ||
const pluginsResult = plugins.map(plugin => computedPluginFiles(plugins, plugin, fileName, sfc, nameToBlock)); | ||
const flatResult = (0, computeds_1.computed)(() => pluginsResult.map(r => r()).flat()); | ||
@@ -47,3 +47,3 @@ const structuredResult = (0, computeds_1.computed)(() => { | ||
for (let i = remain.length - 1; i >= 0; i--) { | ||
const { file, snapshot, mappings, codegenStacks } = remain[i]; | ||
const { file, snapshot, mappings } = remain[i]; | ||
if (!file.parentCodeId) { | ||
@@ -56,3 +56,2 @@ embeddedCodes.push({ | ||
mappings, | ||
codegenStacks, | ||
embeddedCodes: [], | ||
@@ -72,3 +71,2 @@ }); | ||
mappings, | ||
codegenStacks, | ||
embeddedCodes: [], | ||
@@ -96,3 +94,3 @@ }); | ||
exports.computedFiles = computedFiles; | ||
function computedPluginFiles(plugins, plugin, fileName, sfc, nameToBlock, codegenStack) { | ||
function computedPluginFiles(plugins, plugin, fileName, sfc, nameToBlock) { | ||
const embeddedFiles = {}; | ||
@@ -113,4 +111,4 @@ const files = (0, computeds_1.computed)(() => { | ||
embeddedFiles[fileInfo.id] = (0, computeds_1.computed)(() => { | ||
const [content, stacks] = codegenStack ? (0, language_core_1.track)([]) : [[], []]; | ||
const file = new embeddedFile_1.VueEmbeddedCode(fileInfo.id, fileInfo.lang, content, stacks); | ||
const content = []; | ||
const file = new embeddedFile_1.VueEmbeddedCode(fileInfo.id, fileInfo.lang, content); | ||
for (const plugin of plugins) { | ||
@@ -161,4 +159,6 @@ if (!plugin.resolveEmbeddedCode) { | ||
const mappings = (0, language_core_1.buildMappings)(file.content); | ||
const newMappings = []; | ||
let lastValidMapping; | ||
for (const mapping of mappings) { | ||
for (let i = 0; i < mappings.length; i++) { | ||
const mapping = mappings[i]; | ||
if (mapping.source !== undefined) { | ||
@@ -174,3 +174,13 @@ const block = nameToBlock()[mapping.source]; | ||
} | ||
if (mapping.data.__combineLastMapping) { | ||
if (mapping.data.__combineOffsetMapping !== undefined) { | ||
const offsetMapping = mappings[i - mapping.data.__combineOffsetMapping]; | ||
if (typeof offsetMapping === 'string' || !offsetMapping) { | ||
throw new Error('Invalid offset mapping, mappings: ' + mappings.length + ', i: ' + i + ', offset: ' + mapping.data.__combineOffsetMapping); | ||
} | ||
offsetMapping.sourceOffsets.push(...mapping.sourceOffsets); | ||
offsetMapping.generatedOffsets.push(...mapping.generatedOffsets); | ||
offsetMapping.lengths.push(...mapping.lengths); | ||
continue; | ||
} | ||
else if (mapping.data.__combineLastMapping) { | ||
lastValidMapping.sourceOffsets.push(...mapping.sourceOffsets); | ||
@@ -184,2 +194,3 @@ lastValidMapping.generatedOffsets.push(...mapping.generatedOffsets); | ||
} | ||
newMappings.push(mapping); | ||
} | ||
@@ -189,4 +200,3 @@ return { | ||
snapshot, | ||
mappings: mappings.filter(mapping => !mapping.data.__combineLastMapping), | ||
codegenStacks: (0, language_core_1.buildStacks)(file.content, file.contentStacks), | ||
mappings: newMappings, | ||
}; | ||
@@ -193,0 +203,0 @@ }); |
@@ -6,6 +6,6 @@ "use strict"; | ||
const computeds_1 = require("computeds"); | ||
const utils_1 = require("../generators/utils"); | ||
const shared_1 = require("../plugins/shared"); | ||
function computedMappings(snapshot, sfc) { | ||
return (0, computeds_1.computed)(() => { | ||
const str = [[snapshot().getText(0, snapshot().getLength()), undefined, 0, (0, utils_1.enableAllFeatures)({})]]; | ||
const str = [[snapshot().getText(0, snapshot().getLength()), undefined, 0, shared_1.allCodeFeatures]]; | ||
for (const block of [ | ||
@@ -59,3 +59,3 @@ sfc.script, | ||
lengths: offsets.map(() => 0), | ||
data: (0, utils_1.disableAllFeatures)({ structure: true }), | ||
data: { structure: true }, | ||
}); | ||
@@ -62,0 +62,0 @@ } |
@@ -35,3 +35,3 @@ "use strict"; | ||
}); | ||
const scriptSetup = computedNullableSfcBlock('scriptSetup', 'js', (0, computeds_1.computed)(() => parsed()?.descriptor.scriptSetup ?? undefined), (block, base) => { | ||
const scriptSetupOriginal = computedNullableSfcBlock('scriptSetup', 'js', (0, computeds_1.computed)(() => parsed()?.descriptor.scriptSetup ?? undefined), (block, base) => { | ||
const generic = (0, computeds_1.computed)(() => { | ||
@@ -52,2 +52,23 @@ const _block = block(); | ||
}); | ||
const hasScript = (0, computeds_1.computed)(() => !!parsed()?.descriptor.script); | ||
const hasScriptSetup = (0, computeds_1.computed)(() => !!parsed()?.descriptor.scriptSetup); | ||
const scriptSetup = (0, computeds_1.computed)(() => { | ||
if (!hasScript() && !hasScriptSetup()) { | ||
//#region monkey fix: https://github.com/vuejs/language-tools/pull/2113 | ||
return { | ||
content: '', | ||
lang: 'ts', | ||
name: '', | ||
start: 0, | ||
end: 0, | ||
startTagEnd: 0, | ||
endTagStart: 0, | ||
generic: undefined, | ||
genericOffset: 0, | ||
attrs: {}, | ||
ast: ts.createSourceFile('', '', 99, false, ts.ScriptKind.TS), | ||
}; | ||
} | ||
return scriptSetupOriginal(); | ||
}); | ||
const styles = (0, computeds_1.computedArray)((0, computeds_1.computed)(() => parsed()?.descriptor.styles ?? []), (block, i) => { | ||
@@ -54,0 +75,0 @@ const base = computedSfcBlock('style_' + i, 'css', block); |
@@ -1,2 +0,2 @@ | ||
import type { Mapping, StackNode } from '@volar/language-core'; | ||
import type { Mapping } from '@volar/language-core'; | ||
import type { Code } from '../types'; | ||
@@ -7,7 +7,6 @@ export declare class VueEmbeddedCode { | ||
content: Code[]; | ||
contentStacks: StackNode[]; | ||
parentCodeId?: string; | ||
linkedCodeMappings: Mapping[]; | ||
embeddedCodes: VueEmbeddedCode[]; | ||
constructor(id: string, lang: string, content: Code[], contentStacks: StackNode[]); | ||
constructor(id: string, lang: string, content: Code[]); | ||
} |
@@ -5,7 +5,6 @@ "use strict"; | ||
class VueEmbeddedCode { | ||
constructor(id, lang, content, contentStacks) { | ||
constructor(id, lang, content) { | ||
this.id = id; | ||
this.lang = lang; | ||
this.content = content; | ||
this.contentStacks = contentStacks; | ||
this.linkedCodeMappings = []; | ||
@@ -12,0 +11,0 @@ this.embeddedCodes = []; |
@@ -1,6 +0,6 @@ | ||
import type { Stack, VirtualCode } from '@volar/language-core'; | ||
import type { VirtualCode } from '@volar/language-core'; | ||
import { Signal } from 'computeds'; | ||
import type * as ts from 'typescript'; | ||
import type { VueCompilerOptions, VueLanguagePlugin } from '../types'; | ||
export declare class VueGeneratedCode implements VirtualCode { | ||
export declare class VueVirtualCode implements VirtualCode { | ||
fileName: string; | ||
@@ -12,3 +12,2 @@ languageId: string; | ||
ts: typeof import('typescript'); | ||
codegenStack: boolean; | ||
id: string; | ||
@@ -20,8 +19,7 @@ _snapshot: Signal<ts.IScriptSnapshot>; | ||
getEmbeddedCodes: () => VirtualCode[]; | ||
codegenStacks: Stack[]; | ||
get embeddedCodes(): VirtualCode[]; | ||
get snapshot(): ts.IScriptSnapshot; | ||
get mappings(): import("@volar/language-core").CodeMapping[]; | ||
constructor(fileName: string, languageId: string, initSnapshot: ts.IScriptSnapshot, vueCompilerOptions: VueCompilerOptions, plugins: ReturnType<VueLanguagePlugin>[], ts: typeof import('typescript'), codegenStack: boolean); | ||
constructor(fileName: string, languageId: string, initSnapshot: ts.IScriptSnapshot, vueCompilerOptions: VueCompilerOptions, plugins: ReturnType<VueLanguagePlugin>[], ts: typeof import('typescript')); | ||
update(newSnapshot: ts.IScriptSnapshot): void; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.VueGeneratedCode = void 0; | ||
exports.VueVirtualCode = void 0; | ||
const computeds_1 = require("computeds"); | ||
@@ -9,3 +9,4 @@ const computedFiles_1 = require("./computedFiles"); | ||
const computedVueSfc_1 = require("./computedVueSfc"); | ||
class VueGeneratedCode { | ||
class VueVirtualCode { | ||
// others | ||
get embeddedCodes() { | ||
@@ -20,3 +21,3 @@ return this.getEmbeddedCodes(); | ||
} | ||
constructor(fileName, languageId, initSnapshot, vueCompilerOptions, plugins, ts, codegenStack) { | ||
constructor(fileName, languageId, initSnapshot, vueCompilerOptions, plugins, ts) { | ||
this.fileName = fileName; | ||
@@ -28,3 +29,2 @@ this.languageId = languageId; | ||
this.ts = ts; | ||
this.codegenStack = codegenStack; | ||
// sources | ||
@@ -36,5 +36,3 @@ this.id = 'main'; | ||
this.getMappings = (0, computedMappings_1.computedMappings)(() => this._snapshot(), this.sfc); | ||
this.getEmbeddedCodes = (0, computedFiles_1.computedFiles)(this.plugins, this.fileName, this.sfc, this.codegenStack); | ||
// others | ||
this.codegenStacks = []; | ||
this.getEmbeddedCodes = (0, computedFiles_1.computedFiles)(this.plugins, this.fileName, this.sfc); | ||
this._snapshot = (0, computeds_1.signal)(initSnapshot); | ||
@@ -46,3 +44,3 @@ } | ||
} | ||
exports.VueGeneratedCode = VueGeneratedCode; | ||
exports.VueVirtualCode = VueVirtualCode; | ||
//# sourceMappingURL=vueFile.js.map |
{ | ||
"name": "@vue/language-core", | ||
"version": "2.0.13", | ||
"version": "2.0.14", | ||
"license": "MIT", | ||
@@ -15,3 +15,3 @@ "files": [ | ||
"dependencies": { | ||
"@volar/language-core": "2.2.0-alpha.8", | ||
"@volar/language-core": "2.2.0-alpha.10", | ||
"@vue/compiler-dom": "^3.4.0", | ||
@@ -38,3 +38,3 @@ "@vue/shared": "^3.4.0", | ||
}, | ||
"gitHead": "591d019acd0d34e390880d69b31fbc7b794b806b" | ||
"gitHead": "ce1412067f88b7f9af03a2d3e04c220b4921c363" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
283547
112
6319
1
+ Added@volar/language-core@2.2.0-alpha.10(transitive)
+ Added@volar/source-map@2.2.0-alpha.10(transitive)
- Removed@volar/language-core@2.2.0-alpha.8(transitive)
- Removed@volar/source-map@2.2.0-alpha.8(transitive)