@vue/language-core 2.0.7 → 2.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,21 +5,47 @@ const plugin = () => {
5
5
  return {
6
6
  version: 2,
7
7
  getEmbeddedCodes(_fileName, sfc) {
8
- return sfc.styles.map((style, i) => ({
9
- id: 'style_' + i,
10
- lang: style.lang,
11
- }));
8
+ const result = [];
9
+ for (let i = 0; i < sfc.styles.length; i++) {
10
+ const style = sfc.styles[i];
11
+ if (style) {
12
+ result.push({
13
+ id: 'style_' + i,
14
+ lang: style.lang,
15
+ });
16
+ if (style.cssVars.length) {
17
+ result.push({
18
+ id: 'style_' + i + '_inline_ts',
19
+ lang: 'ts',
20
+ });
21
+ }
22
+ }
23
+ }
24
+ return result;
12
25
  },
13
26
  resolveEmbeddedCode(_fileName, sfc, embeddedFile) {
14
27
  if (embeddedFile.id.startsWith('style_')) {
15
- const index = parseInt(embeddedFile.id.slice('style_'.length));
28
+ const index = parseInt(embeddedFile.id.split('_')[1]);
16
29
  const style = sfc.styles[index];
17
- embeddedFile.content.push([
18
- style.content,
19
- style.name,
20
- 0,
21
- (0, utils_1.enableAllFeatures)({}),
22
- ]);
30
+ if (embeddedFile.id.endsWith('_inline_ts')) {
31
+ embeddedFile.parentCodeId = 'style_' + index;
32
+ for (const cssVar of style.cssVars) {
33
+ embeddedFile.content.push('(', [
34
+ cssVar.text,
35
+ style.name,
36
+ cssVar.offset,
37
+ (0, utils_1.enableAllFeatures)({}),
38
+ ], ');\n');
39
+ }
40
+ }
41
+ else {
42
+ embeddedFile.content.push([
43
+ style.content,
44
+ style.name,
45
+ 0,
46
+ (0, utils_1.enableAllFeatures)({}),
47
+ ]);
48
+ }
23
49
  }
24
50
  },
25
51
  };
@@ -0,0 +1,3 @@
1
+ import type { VueLanguagePlugin } from '../types';
2
+ declare const plugin: VueLanguagePlugin;
3
+ export default plugin;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const inlineCss_1 = require("../generators/inlineCss");
4
+ const plugin = () => {
5
+ return {
6
+ version: 2,
7
+ getEmbeddedCodes(_fileName, sfc) {
8
+ if (!sfc.template?.ast) {
9
+ return [];
10
+ }
11
+ return [{ id: 'template_inline_css', lang: 'css' }];
12
+ },
13
+ resolveEmbeddedCode(_fileName, sfc, embeddedFile) {
14
+ if (embeddedFile.id !== 'template_inline_css' || !sfc.template?.ast) {
15
+ return;
16
+ }
17
+ embeddedFile.parentCodeId = 'template';
18
+ embeddedFile.content.push(...(0, inlineCss_1.generate)(sfc.template.ast));
19
+ },
20
+ };
21
+ };
22
+ exports.default = plugin;
23
+ //# sourceMappingURL=vue-template-inline-css.js.map
@@ -0,0 +1,3 @@
1
+ import type { VueLanguagePlugin } from '../types';
2
+ declare const plugin: VueLanguagePlugin;
3
+ export default plugin;
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const template_1 = require("../generators/template");
4
+ const utils_1 = require("../generators/utils");
5
+ const CompilerDOM = require("@vue/compiler-dom");
6
+ const codeFeatures = (0, utils_1.disableAllFeatures)({
7
+ format: true,
8
+ // autoInserts: true, // TODO: support vue-autoinsert-parentheses
9
+ });
10
+ const formatBrackets = {
11
+ normal: ['`${', '}`;'],
12
+ if: ['if (', ') { }'],
13
+ for: ['for (', ') { }'],
14
+ // fix https://github.com/vuejs/language-tools/issues/3572
15
+ params: ['(', ') => {};'],
16
+ // fix https://github.com/vuejs/language-tools/issues/1210
17
+ // fix https://github.com/vuejs/language-tools/issues/2305
18
+ curly: ['0 +', '+ 0;'],
19
+ event: ['() => ', ';'],
20
+ };
21
+ const plugin = ctx => {
22
+ const parseds = new WeakMap();
23
+ return {
24
+ version: 2,
25
+ getEmbeddedCodes(_fileName, sfc) {
26
+ if (!sfc.template?.ast) {
27
+ return [];
28
+ }
29
+ const parsed = parse(sfc);
30
+ parseds.set(sfc, parsed);
31
+ const result = [];
32
+ for (const [id] of parsed) {
33
+ result.push({ id, lang: 'ts' });
34
+ }
35
+ return result;
36
+ },
37
+ resolveEmbeddedCode(_fileName, sfc, embeddedFile) {
38
+ // access template content to watch change
39
+ (() => sfc.template?.content)();
40
+ const parsed = parseds.get(sfc);
41
+ if (parsed) {
42
+ const codes = parsed.get(embeddedFile.id);
43
+ if (codes) {
44
+ embeddedFile.content.push(...codes);
45
+ embeddedFile.parentCodeId = 'template';
46
+ }
47
+ }
48
+ },
49
+ };
50
+ function parse(sfc) {
51
+ const data = new Map();
52
+ if (!sfc.template?.ast) {
53
+ return data;
54
+ }
55
+ const templateContent = sfc.template.content;
56
+ let i = 0;
57
+ sfc.template.ast.children.forEach(visit);
58
+ return data;
59
+ function visit(node) {
60
+ if (node.type === CompilerDOM.NodeTypes.ELEMENT) {
61
+ for (const prop of node.props) {
62
+ if (prop.type !== CompilerDOM.NodeTypes.DIRECTIVE) {
63
+ continue;
64
+ }
65
+ const isShorthand = prop.arg?.loc.start.offset === prop.exp?.loc.start.offset; // vue 3.4+
66
+ if (isShorthand) {
67
+ continue;
68
+ }
69
+ if (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && !prop.arg.isStatic) {
70
+ addFormatCodes(prop.arg.content, prop.arg.loc.start.offset, formatBrackets.normal);
71
+ }
72
+ if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
73
+ && prop.exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY // style='z-index: 2' will compile to {'z-index':'2'}
74
+ ) {
75
+ if (prop.name === 'on') {
76
+ const ast = (0, template_1.createTsAst)(ctx.modules.typescript, prop.exp, prop.exp.content);
77
+ addFormatCodes(prop.exp.content, prop.exp.loc.start.offset, (0, template_1.isCompoundExpression)(ctx.modules.typescript, ast)
78
+ ? formatBrackets.event
79
+ : formatBrackets.normal);
80
+ }
81
+ else {
82
+ addFormatCodes(prop.exp.content, prop.exp.loc.start.offset, formatBrackets.normal);
83
+ }
84
+ }
85
+ }
86
+ for (const child of node.children) {
87
+ visit(child);
88
+ }
89
+ }
90
+ else if (node.type === CompilerDOM.NodeTypes.IF) {
91
+ for (let i = 0; i < node.branches.length; i++) {
92
+ const branch = node.branches[i];
93
+ if (branch.condition?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
94
+ addFormatCodes(branch.condition.content, branch.condition.loc.start.offset, formatBrackets.if);
95
+ }
96
+ for (const childNode of branch.children) {
97
+ visit(childNode);
98
+ }
99
+ }
100
+ }
101
+ else if (node.type === CompilerDOM.NodeTypes.FOR) {
102
+ const { leftExpressionRange, leftExpressionText } = (0, template_1.parseVForNode)(node);
103
+ const { source } = node.parseResult;
104
+ if (leftExpressionRange && leftExpressionText && source.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
105
+ const start = leftExpressionRange.start;
106
+ const end = source.loc.start.offset + source.content.length;
107
+ addFormatCodes(templateContent.substring(start, end), start, formatBrackets.for);
108
+ }
109
+ for (const child of node.children) {
110
+ visit(child);
111
+ }
112
+ }
113
+ else if (node.type === CompilerDOM.NodeTypes.TEXT_CALL) {
114
+ // {{ var }}
115
+ visit(node.content);
116
+ }
117
+ else if (node.type === CompilerDOM.NodeTypes.COMPOUND_EXPRESSION) {
118
+ // {{ ... }} {{ ... }}
119
+ for (const childNode of node.children) {
120
+ if (typeof childNode === 'object') {
121
+ visit(childNode);
122
+ }
123
+ }
124
+ }
125
+ else if (node.type === CompilerDOM.NodeTypes.INTERPOLATION) {
126
+ // {{ ... }}
127
+ const [content, start] = (0, template_1.parseInterpolationNode)(node, templateContent);
128
+ const lines = content.split('\n');
129
+ addFormatCodes(content, start, lines.length <= 1 ? formatBrackets.curly : [
130
+ lines[0].trim() === '' ? '(' : formatBrackets.curly[0],
131
+ lines[lines.length - 1].trim() === '' ? ');' : formatBrackets.curly[1],
132
+ ]);
133
+ }
134
+ }
135
+ function addFormatCodes(code, offset, wrapper) {
136
+ const id = 'template_inline_ts_' + i++;
137
+ data.set(id, [
138
+ wrapper[0],
139
+ [
140
+ code,
141
+ 'template',
142
+ offset,
143
+ codeFeatures,
144
+ ],
145
+ wrapper[1],
146
+ ]);
147
+ }
148
+ }
149
+ };
150
+ exports.default = plugin;
151
+ //# sourceMappingURL=vue-template-inline-ts.js.map
@@ -53,6 +53,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
53
53
  name: import("../types").TextRange | undefined;
54
54
  nameIsString: boolean;
55
55
  type: import("../types").TextRange | undefined;
56
+ modifierType?: import("../types").TextRange | undefined;
56
57
  defaultValue: import("../types").TextRange | undefined;
57
58
  required: boolean;
58
59
  isModel?: boolean | undefined;
@@ -67,10 +68,6 @@ export declare const tsCodegen: WeakMap<Sfc, {
67
68
  generatedTemplate: () => {
68
69
  codes: Code[];
69
70
  codeStacks: string[];
70
- formatCodes: Code[];
71
- formatCodeStacks: string[];
72
- cssCodes: Code[];
73
- cssCodeStacks: string[];
74
71
  tagOffsetsMap: Map<string, number[]>;
75
72
  accessedGlobalVariables: Set<string>;
76
73
  hasSlot: boolean;
@@ -5,7 +5,6 @@ const language_core_1 = require("@volar/language-core");
5
5
  const computeds_1 = require("computeds");
6
6
  const script_1 = require("../generators/script");
7
7
  const template_1 = require("../generators/template");
8
- const utils_1 = require("../generators/utils");
9
8
  const scriptRanges_1 = require("../parsers/scriptRanges");
10
9
  const scriptSetupRanges_1 = require("../parsers/scriptSetupRanges");
11
10
  exports.tsCodegen = new WeakMap();
@@ -22,10 +21,6 @@ const plugin = ctx => {
22
21
  if (['js', 'ts', 'jsx', 'tsx'].includes(tsx.lang())) {
23
22
  files.push({ id: 'script_' + tsx.lang(), lang: tsx.lang() });
24
23
  }
25
- if (sfc.template) {
26
- files.push({ id: 'template_format', lang: 'ts' });
27
- files.push({ id: 'template_style', lang: 'css' });
28
- }
29
24
  return files;
30
25
  },
31
26
  resolveEmbeddedCode(fileName, sfc, embeddedFile) {
@@ -34,52 +29,11 @@ const plugin = ctx => {
34
29
  const tsx = _tsx.generatedScript();
35
30
  if (tsx) {
36
31
  const [content, contentStacks] = ctx.codegenStack ? (0, language_core_1.track)([...tsx.codes], [...tsx.codeStacks]) : [[...tsx.codes], [...tsx.codeStacks]];
37
- content.forEach(code => {
38
- if (typeof code !== 'string') {
39
- code[3].structure = false;
40
- code[3].format = false;
41
- }
42
- });
43
32
  embeddedFile.content = content;
44
33
  embeddedFile.contentStacks = contentStacks;
45
34
  embeddedFile.linkedCodeMappings = [...tsx.linkedCodeMappings];
46
35
  }
47
36
  }
48
- else if (embeddedFile.id === 'template_format') {
49
- embeddedFile.parentCodeId = 'template';
50
- const template = _tsx.generatedTemplate();
51
- if (template) {
52
- const [content, contentStacks] = ctx.codegenStack
53
- ? (0, language_core_1.track)([...template.formatCodes], template.formatCodeStacks.map(stack => ({ stack, length: 1 })))
54
- : [[...template.formatCodes], template.formatCodeStacks.map(stack => ({ stack, length: 1 }))];
55
- embeddedFile.content = content;
56
- embeddedFile.contentStacks = contentStacks;
57
- }
58
- for (const style of sfc.styles) {
59
- embeddedFile.content.push('\n\n');
60
- for (const cssVar of style.cssVars) {
61
- embeddedFile.content.push('(');
62
- embeddedFile.content.push([
63
- cssVar.text,
64
- style.name,
65
- cssVar.offset,
66
- (0, utils_1.enableAllFeatures)({}),
67
- ]);
68
- embeddedFile.content.push(');\n');
69
- }
70
- }
71
- }
72
- else if (embeddedFile.id === 'template_style') {
73
- embeddedFile.parentCodeId = 'template';
74
- const template = _tsx.generatedTemplate();
75
- if (template) {
76
- const [content, contentStacks] = ctx.codegenStack
77
- ? (0, language_core_1.track)([...template.cssCodes], template.cssCodeStacks.map(stack => ({ stack, length: 1 })))
78
- : [[...template.cssCodes], template.cssCodeStacks.map(stack => ({ stack, length: 1 }))];
79
- embeddedFile.content = content;
80
- embeddedFile.contentStacks = contentStacks;
81
- }
82
- }
83
37
  },
84
38
  };
85
39
  function useTsx(fileName, sfc) {
@@ -130,34 +84,14 @@ function createTsx(fileName, _sfc, ctx) {
130
84
  return;
131
85
  }
132
86
  const tsCodes = [];
133
- const tsFormatCodes = [];
134
- const inlineCssCodes = [];
135
87
  const tsCodegenStacks = [];
136
- const tsFormatCodegenStacks = [];
137
- const inlineCssCodegenStacks = [];
138
88
  const codegen = (0, template_1.generate)(ts, ctx.compilerOptions, ctx.vueCompilerOptions, _sfc.template, shouldGenerateScopedClasses(), stylesScopedClasses(), hasScriptSetupSlots(), slotsAssignName(), propsAssignName(), ctx.codegenStack);
139
89
  let current = codegen.next();
140
90
  while (!current.done) {
141
- const [type, code, stack] = current.value;
142
- if (type === 'ts') {
143
- tsCodes.push(code);
144
- }
145
- else if (type === 'tsFormat') {
146
- tsFormatCodes.push(code);
147
- }
148
- else if (type === 'inlineCss') {
149
- inlineCssCodes.push(code);
150
- }
91
+ const [code, stack] = current.value;
92
+ tsCodes.push(code);
151
93
  if (ctx.codegenStack) {
152
- if (type === 'ts') {
153
- tsCodegenStacks.push(stack);
154
- }
155
- else if (type === 'tsFormat') {
156
- tsFormatCodegenStacks.push(stack);
157
- }
158
- else if (type === 'inlineCss') {
159
- inlineCssCodegenStacks.push(stack);
160
- }
94
+ tsCodegenStacks.push(stack);
161
95
  }
162
96
  current = codegen.next();
163
97
  }
@@ -165,10 +99,6 @@ function createTsx(fileName, _sfc, ctx) {
165
99
  ...current.value,
166
100
  codes: tsCodes,
167
101
  codeStacks: tsCodegenStacks,
168
- formatCodes: tsFormatCodes,
169
- formatCodeStacks: tsFormatCodegenStacks,
170
- cssCodes: inlineCssCodes,
171
- cssCodeStacks: inlineCssCodegenStacks,
172
102
  };
173
103
  });
174
104
  const hasScriptSetupSlots = (0, computeds_1.computed)(() => !!scriptSetupRanges()?.slots.define);
package/lib/plugins.js CHANGED
@@ -9,6 +9,8 @@ const vue_sfc_scripts_1 = require("./plugins/vue-sfc-scripts");
9
9
  const vue_sfc_styles_1 = require("./plugins/vue-sfc-styles");
10
10
  const vue_sfc_template_1 = require("./plugins/vue-sfc-template");
11
11
  const vue_template_html_1 = require("./plugins/vue-template-html");
12
+ const vue_template_inline_css_1 = require("./plugins/vue-template-inline-css");
13
+ const vue_template_inline_ts_1 = require("./plugins/vue-template-inline-ts");
12
14
  const vue_tsx_1 = require("./plugins/vue-tsx");
13
15
  const types_1 = require("./types");
14
16
  function getDefaultVueLanguagePlugins(pluginContext) {
@@ -17,6 +19,8 @@ function getDefaultVueLanguagePlugins(pluginContext) {
17
19
  file_html_1.default, // .html for PetiteVue
18
20
  file_vue_1.default, // .vue and others for Vue
19
21
  vue_template_html_1.default,
22
+ vue_template_inline_css_1.default,
23
+ vue_template_inline_ts_1.default,
20
24
  vue_sfc_styles_1.default,
21
25
  vue_sfc_customblocks_1.default,
22
26
  vue_sfc_scripts_1.default,
@@ -36,16 +36,7 @@ function computedFiles(plugins, fileName, sfc, codegenStack) {
36
36
  break;
37
37
  }
38
38
  }
39
- for (const { file, snapshot, mappings, codegenStacks } of remain) {
40
- embeddedCodes.push({
41
- id: file.id,
42
- languageId: (0, language_core_1.resolveCommonLanguageId)(`/dummy.${file.lang}`),
43
- linkedCodeMappings: file.linkedCodeMappings,
44
- snapshot,
45
- mappings,
46
- codegenStacks,
47
- embeddedCodes: [],
48
- });
39
+ for (const { file } of remain) {
49
40
  console.error('Unable to resolve embedded: ' + file.parentCodeId + ' -> ' + file.id);
50
41
  }
51
42
  return embeddedCodes;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-core",
3
- "version": "2.0.7",
3
+ "version": "2.0.10",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -12,7 +12,7 @@
12
12
  "directory": "packages/language-core"
13
13
  },
14
14
  "dependencies": {
15
- "@volar/language-core": "~2.1.3",
15
+ "@volar/language-core": "~2.2.0-alpha.5",
16
16
  "@vue/compiler-dom": "^3.4.0",
17
17
  "@vue/shared": "^3.4.0",
18
18
  "computeds": "^0.0.1",
@@ -34,5 +34,5 @@
34
34
  "optional": true
35
35
  }
36
36
  },
37
- "gitHead": "4a37e8f3ebcf31ecfd2ea627f7611d5990ec5df6"
37
+ "gitHead": "a20a2ee950b63a949660b7e8faf0faed0e5bad33"
38
38
  }