@vue/language-core 3.0.5 → 3.0.7-alpha.0

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.
Files changed (56) hide show
  1. package/index.d.ts +1 -1
  2. package/index.js +1 -1
  3. package/lib/codegen/codeFeatures.d.ts +0 -5
  4. package/lib/codegen/codeFeatures.js +0 -3
  5. package/lib/codegen/script/component.d.ts +1 -1
  6. package/lib/codegen/script/component.js +10 -14
  7. package/lib/codegen/script/componentSelf.js +19 -23
  8. package/lib/codegen/script/index.d.ts +20 -3
  9. package/lib/codegen/script/index.js +10 -16
  10. package/lib/codegen/script/scriptSetup.js +1 -1
  11. package/lib/codegen/script/template.d.ts +0 -1
  12. package/lib/codegen/script/template.js +6 -43
  13. package/lib/codegen/template/element.js +4 -18
  14. package/lib/codegen/template/elementDirectives.js +3 -1
  15. package/lib/codegen/template/index.d.ts +63 -3
  16. package/lib/codegen/template/index.js +21 -21
  17. package/lib/codegen/template/interpolation.js +19 -5
  18. package/lib/codegen/template/slotOutlet.js +2 -2
  19. package/lib/codegen/template/styleScopedClasses.js +6 -10
  20. package/lib/codegen/template/vSlot.js +15 -25
  21. package/lib/{utils/ts.d.ts → compilerOptions.d.ts} +8 -8
  22. package/lib/compilerOptions.js +294 -0
  23. package/lib/plugins/file-html.js +1 -1
  24. package/lib/plugins/file-md.js +1 -1
  25. package/lib/plugins/file-vue.js +1 -1
  26. package/lib/plugins/vue-root-tags.js +1 -1
  27. package/lib/plugins/vue-script-js.js +1 -1
  28. package/lib/plugins/vue-sfc-customblocks.js +1 -1
  29. package/lib/plugins/vue-sfc-scripts.js +1 -1
  30. package/lib/plugins/vue-sfc-styles.js +5 -5
  31. package/lib/plugins/vue-sfc-template.js +1 -1
  32. package/lib/plugins/vue-template-html.js +1 -1
  33. package/lib/plugins/vue-template-inline-css.js +1 -1
  34. package/lib/plugins/vue-template-inline-ts.js +1 -1
  35. package/lib/plugins/vue-tsx.d.ts +5 -5
  36. package/lib/plugins/vue-tsx.js +7 -26
  37. package/lib/plugins.js +2 -0
  38. package/lib/types.d.ts +3 -2
  39. package/lib/types.js +1 -1
  40. package/lib/utils/shared.d.ts +3 -1
  41. package/lib/utils/shared.js +13 -0
  42. package/lib/utils/ts.js +43 -66
  43. package/lib/virtualFile/computedSfc.js +13 -8
  44. package/package.json +4 -4
  45. package/lib/codegen/tenp.d.ts +0 -1
  46. package/lib/codegen/tenp.js +0 -3
  47. package/lib/parsers/utils.d.ts +0 -12
  48. package/lib/parsers/utils.js +0 -95
  49. package/lib/plugins/file-css.d.ts +0 -3
  50. package/lib/plugins/file-css.js +0 -57
  51. package/lib/utils/parseCssClassNames.d.ts +0 -4
  52. package/lib/utils/parseCssClassNames.js +0 -17
  53. package/lib/utils/parseCssImports.d.ts +0 -4
  54. package/lib/utils/parseCssImports.js +0 -19
  55. package/lib/utils/parseCssVars.d.ts +0 -6
  56. package/lib/utils/parseCssVars.js +0 -26
@@ -6,16 +6,16 @@ const alien_signals_1 = require("alien-signals");
6
6
  const path = require("path-browserify");
7
7
  const script_1 = require("../codegen/script");
8
8
  const template_1 = require("../codegen/template");
9
+ const compilerOptions_1 = require("../compilerOptions");
9
10
  const scriptRanges_1 = require("../parsers/scriptRanges");
10
11
  const scriptSetupRanges_1 = require("../parsers/scriptSetupRanges");
11
12
  const vueCompilerOptions_1 = require("../parsers/vueCompilerOptions");
12
13
  const signals_1 = require("../utils/signals");
13
- const ts_1 = require("../utils/ts");
14
14
  exports.tsCodegen = new WeakMap();
15
15
  const validLangs = new Set(['js', 'jsx', 'ts', 'tsx']);
16
16
  const plugin = ctx => {
17
17
  return {
18
- version: 2.1,
18
+ version: 2.2,
19
19
  requiredCompilerOptions: [
20
20
  'noPropertyAccessFromIndexSignature',
21
21
  'exactOptionalPropertyTypes',
@@ -68,7 +68,7 @@ function createTsx(fileName, sfc, ctx) {
68
68
  const getResolvedOptions = (0, alien_signals_1.computed)(() => {
69
69
  const options = (0, vueCompilerOptions_1.parseVueCompilerOptions)(sfc.comments);
70
70
  if (options) {
71
- const resolver = new ts_1.CompilerOptionsResolver();
71
+ const resolver = new compilerOptions_1.CompilerOptionsResolver();
72
72
  resolver.addConfig(options, path.dirname(fileName));
73
73
  return resolver.build(ctx.vueCompilerOptions);
74
74
  }
@@ -144,7 +144,7 @@ function createTsx(fileName, sfc, ctx) {
144
144
  if (getResolvedOptions().skipTemplateCodegen || !sfc.template) {
145
145
  return;
146
146
  }
147
- const options = {
147
+ return (0, template_1.generateTemplate)({
148
148
  ts,
149
149
  compilerOptions: ctx.compilerOptions,
150
150
  vueCompilerOptions: getResolvedOptions(),
@@ -158,23 +158,10 @@ function createTsx(fileName, sfc, ctx) {
158
158
  propsAssignName: getSetupPropsAssignName(),
159
159
  inheritAttrs: getSetupInheritAttrs(),
160
160
  selfComponentName: getComponentSelfName(),
161
- };
162
- const context = (0, template_1.createTemplateCodegenContext)(options, sfc.template.ast);
163
- const codegen = (0, template_1.generateTemplate)(options, context);
164
- const codes = [];
165
- for (const code of codegen) {
166
- if (typeof code === 'object') {
167
- code[3] = context.resolveCodeFeatures(code[3]);
168
- }
169
- codes.push(code);
170
- }
171
- return {
172
- ...context,
173
- codes,
174
- };
161
+ });
175
162
  });
176
163
  const getGeneratedScript = (0, alien_signals_1.computed)(() => {
177
- const options = {
164
+ return (0, script_1.generateScript)({
178
165
  ts,
179
166
  compilerOptions: ctx.compilerOptions,
180
167
  vueCompilerOptions: getResolvedOptions(),
@@ -186,13 +173,7 @@ function createTsx(fileName, sfc, ctx) {
186
173
  templateCodegen: getGeneratedTemplate(),
187
174
  destructuredPropNames: getSetupDestructuredPropNames(),
188
175
  templateRefNames: getSetupTemplateRefNames(),
189
- };
190
- const context = (0, script_1.createScriptCodegenContext)(options);
191
- const codegen = (0, script_1.generateScript)(options, context);
192
- return {
193
- ...context,
194
- codes: [...codegen],
195
- };
176
+ });
196
177
  });
197
178
  return {
198
179
  getLang,
package/lib/plugins.js CHANGED
@@ -24,6 +24,7 @@ const vue_sfc_customblocks_1 = require("./plugins/vue-sfc-customblocks");
24
24
  const vue_sfc_scripts_1 = require("./plugins/vue-sfc-scripts");
25
25
  const vue_sfc_styles_1 = require("./plugins/vue-sfc-styles");
26
26
  const vue_sfc_template_1 = require("./plugins/vue-sfc-template");
27
+ const vue_style_css_1 = require("./plugins/vue-style-css");
27
28
  const vue_template_html_1 = require("./plugins/vue-template-html");
28
29
  const vue_template_inline_css_1 = require("./plugins/vue-template-inline-css");
29
30
  const vue_template_inline_ts_1 = require("./plugins/vue-template-inline-ts");
@@ -37,6 +38,7 @@ function createPlugins(pluginContext) {
37
38
  file_html_1.default,
38
39
  vue_root_tags_1.default,
39
40
  vue_script_js_1.default,
41
+ vue_style_css_1.default,
40
42
  vue_template_html_1.default,
41
43
  vue_template_inline_css_1.default,
42
44
  vue_template_inline_ts_1.default,
package/lib/types.d.ts CHANGED
@@ -63,7 +63,7 @@ export interface VueCompilerOptions {
63
63
  plugins: VueLanguagePlugin[];
64
64
  experimentalModelPropName: Record<string, Record<string, boolean | Record<string, string> | Record<string, string>[]>>;
65
65
  }
66
- export declare const validVersions: readonly [2, 2.1];
66
+ export declare const validVersions: readonly [2, 2.1, 2.2];
67
67
  export type VueLanguagePluginReturn = {
68
68
  version: typeof validVersions[number];
69
69
  name?: string;
@@ -81,6 +81,7 @@ export type VueLanguagePluginReturn = {
81
81
  resolveTemplateCompilerOptions?(options: CompilerDOM.CompilerOptions): CompilerDOM.CompilerOptions;
82
82
  compileSFCScript?(lang: string, script: string): ts.SourceFile | undefined;
83
83
  compileSFCTemplate?(lang: string, template: string, options: CompilerDOM.CompilerOptions): CompilerDOM.CodegenResult | undefined;
84
+ compileSFCStyle?(lang: string, style: string): Pick<Sfc['styles'][number], 'imports' | 'bindings' | 'classNames'> | undefined;
84
85
  updateSFCTemplate?(oldResult: CompilerDOM.CodegenResult, textChange: {
85
86
  start: number;
86
87
  end: number;
@@ -139,7 +140,7 @@ export interface Sfc {
139
140
  text: string;
140
141
  offset: number;
141
142
  }[];
142
- cssVars: {
143
+ bindings: {
143
144
  text: string;
144
145
  offset: number;
145
146
  }[];
package/lib/types.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validVersions = void 0;
4
- exports.validVersions = [2, 2.1];
4
+ exports.validVersions = [2, 2.1, 2.2];
5
5
  //# sourceMappingURL=types.js.map
@@ -1,7 +1,9 @@
1
+ import type * as CompilerDOM from '@vue/compiler-dom';
1
2
  import type * as ts from 'typescript';
2
- import type { TextRange } from '../types';
3
+ import type { Sfc, TextRange } from '../types';
3
4
  export { hyphenate as hyphenateTag } from '@vue/shared';
4
5
  export declare function hyphenateAttr(str: string): string;
5
6
  export declare function getSlotsPropertyName(vueVersion: number): "$scopedSlots" | "$slots";
7
+ export declare function getElementTagOffsets(node: CompilerDOM.ElementNode, template: NonNullable<Sfc['template']>): number[];
6
8
  export declare function getStartEnd(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): TextRange;
7
9
  export declare function getNodeText(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): string;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.hyphenateTag = void 0;
4
4
  exports.hyphenateAttr = hyphenateAttr;
5
5
  exports.getSlotsPropertyName = getSlotsPropertyName;
6
+ exports.getElementTagOffsets = getElementTagOffsets;
6
7
  exports.getStartEnd = getStartEnd;
7
8
  exports.getNodeText = getNodeText;
8
9
  const shared_1 = require("@vue/shared");
@@ -19,6 +20,18 @@ function hyphenateAttr(str) {
19
20
  function getSlotsPropertyName(vueVersion) {
20
21
  return vueVersion < 3 ? '$scopedSlots' : '$slots';
21
22
  }
23
+ function getElementTagOffsets(node, template) {
24
+ const tagOffsets = [
25
+ template.content.indexOf(node.tag, node.loc.start.offset),
26
+ ];
27
+ if (!node.isSelfClosing && template.lang === 'html') {
28
+ const endTagOffset = node.loc.start.offset + node.loc.source.lastIndexOf(node.tag);
29
+ if (endTagOffset > tagOffsets[0]) {
30
+ tagOffsets.push(endTagOffset);
31
+ }
32
+ }
33
+ return tagOffsets;
34
+ }
22
35
  function getStartEnd(ts, node, ast) {
23
36
  return {
24
37
  start: ts.getTokenPosOfNode(node, ast),
package/lib/utils/ts.js CHANGED
@@ -8,15 +8,26 @@ exports.writeGlobalTypes = writeGlobalTypes;
8
8
  const shared_1 = require("@vue/shared");
9
9
  const path_browserify_1 = require("path-browserify");
10
10
  const globalTypes_1 = require("../codegen/globalTypes");
11
- const languagePlugin_1 = require("../languagePlugin");
12
11
  const shared_2 = require("./shared");
13
- function createParsedCommandLineByJson(ts, parseConfigHost, rootDir, json, configFileName = rootDir + '/jsconfig.json') {
14
- const proxyHost = proxyParseConfigHostForExtendConfigPaths(parseConfigHost);
15
- ts.parseJsonConfigFileContent(json, proxyHost.host, rootDir, {}, configFileName);
16
- const resolver = new CompilerOptionsResolver(parseConfigHost.fileExists);
17
- for (const extendPath of proxyHost.extendConfigPaths.reverse()) {
12
+ function createParsedCommandLineByJson(ts, host, rootDir, json, configFileName) {
13
+ const extendedPaths = new Set();
14
+ const proxyHost = {
15
+ ...host,
16
+ readFile(fileName) {
17
+ if (!fileName.endsWith('/package.json')) {
18
+ extendedPaths.add(fileName);
19
+ }
20
+ return host.readFile(fileName);
21
+ },
22
+ readDirectory() {
23
+ return [];
24
+ },
25
+ };
26
+ const parsed = ts.parseJsonConfigFileContent(json, proxyHost, rootDir, {}, configFileName);
27
+ const resolver = new CompilerOptionsResolver(host.fileExists);
28
+ for (const extendPath of [...extendedPaths].reverse()) {
18
29
  try {
19
- const configFile = ts.readJsonConfigFile(extendPath, proxyHost.host.readFile);
30
+ const configFile = ts.readJsonConfigFile(extendPath, host.readFile);
20
31
  const obj = ts.convertToObject(configFile, []);
21
32
  const rawOptions = obj?.vueCompilerOptions ?? {};
22
33
  resolver.addConfig(rawOptions, path_browserify_1.posix.dirname(configFile.fileName));
@@ -25,82 +36,48 @@ function createParsedCommandLineByJson(ts, parseConfigHost, rootDir, json, confi
25
36
  }
26
37
  // ensure the rootDir is added to the config roots
27
38
  resolver.addConfig({}, rootDir);
28
- const resolvedVueOptions = resolver.build();
29
- const parsed = ts.parseJsonConfigFileContent(json, proxyHost.host, rootDir, {}, configFileName, undefined, (0, languagePlugin_1.getAllExtensions)(resolvedVueOptions)
30
- .map(extension => ({
31
- extension: extension.slice(1),
32
- isMixedContent: true,
33
- scriptKind: ts.ScriptKind.Deferred,
34
- })));
35
- // fix https://github.com/vuejs/language-tools/issues/1786
36
- // https://github.com/microsoft/TypeScript/issues/30457
37
- // patching ts server broke with outDir + rootDir + composite/incremental
38
- parsed.options.outDir = undefined;
39
39
  return {
40
40
  ...parsed,
41
- vueOptions: resolvedVueOptions,
41
+ vueOptions: resolver.build(),
42
42
  };
43
43
  }
44
- function createParsedCommandLine(ts, parseConfigHost, tsConfigPath) {
44
+ function createParsedCommandLine(ts, host, configFileName) {
45
45
  try {
46
- const rootDir = path_browserify_1.posix.dirname(tsConfigPath);
47
- const proxyHost = proxyParseConfigHostForExtendConfigPaths(parseConfigHost);
48
- const config = ts.readJsonConfigFile(tsConfigPath, proxyHost.host.readFile);
49
- ts.parseJsonSourceFileConfigFileContent(config, proxyHost.host, rootDir, {}, tsConfigPath);
50
- const resolver = new CompilerOptionsResolver(parseConfigHost.fileExists);
51
- for (const extendPath of proxyHost.extendConfigPaths.reverse()) {
46
+ const extendedPaths = new Set();
47
+ const proxyHost = {
48
+ ...host,
49
+ readFile(fileName) {
50
+ if (!fileName.endsWith('/package.json')) {
51
+ extendedPaths.add(fileName);
52
+ }
53
+ return host.readFile(fileName);
54
+ },
55
+ readDirectory() {
56
+ return [];
57
+ },
58
+ };
59
+ const config = ts.readJsonConfigFile(configFileName, proxyHost.readFile);
60
+ const parsed = ts.parseJsonSourceFileConfigFileContent(config, proxyHost, path_browserify_1.posix.dirname(configFileName), {}, configFileName);
61
+ const resolver = new CompilerOptionsResolver(host.fileExists);
62
+ for (const extendPath of [...extendedPaths].reverse()) {
52
63
  try {
53
- const configFile = ts.readJsonConfigFile(extendPath, proxyHost.host.readFile);
64
+ const configFile = ts.readJsonConfigFile(extendPath, host.readFile);
54
65
  const obj = ts.convertToObject(configFile, []);
55
66
  const rawOptions = obj?.vueCompilerOptions ?? {};
56
67
  resolver.addConfig(rawOptions, path_browserify_1.posix.dirname(configFile.fileName));
57
68
  }
58
69
  catch { }
59
70
  }
60
- const resolvedVueOptions = resolver.build();
61
- const parsed = ts.parseJsonSourceFileConfigFileContent(config, proxyHost.host, path_browserify_1.posix.dirname(tsConfigPath), {}, tsConfigPath, undefined, (0, languagePlugin_1.getAllExtensions)(resolvedVueOptions)
62
- .map(extension => ({
63
- extension: extension.slice(1),
64
- isMixedContent: true,
65
- scriptKind: ts.ScriptKind.Deferred,
66
- })));
67
- // fix https://github.com/vuejs/language-tools/issues/1786
68
- // https://github.com/microsoft/TypeScript/issues/30457
69
- // patching ts server broke with outDir + rootDir + composite/incremental
70
- parsed.options.outDir = undefined;
71
71
  return {
72
72
  ...parsed,
73
- vueOptions: resolvedVueOptions,
74
- };
75
- }
76
- catch {
77
- // console.warn('Failed to resolve tsconfig path:', tsConfigPath, err);
78
- return {
79
- fileNames: [],
80
- options: {},
81
- vueOptions: getDefaultCompilerOptions(),
82
- errors: [],
73
+ vueOptions: resolver.build(),
83
74
  };
84
75
  }
85
- }
86
- function proxyParseConfigHostForExtendConfigPaths(parseConfigHost) {
87
- const extendConfigPaths = [];
88
- const host = new Proxy(parseConfigHost, {
89
- get(target, key) {
90
- if (key === 'readFile') {
91
- return (fileName) => {
92
- if (!fileName.endsWith('/package.json') && !extendConfigPaths.includes(fileName)) {
93
- extendConfigPaths.push(fileName);
94
- }
95
- return target.readFile(fileName);
96
- };
97
- }
98
- return target[key];
99
- },
100
- });
76
+ catch { }
101
77
  return {
102
- host,
103
- extendConfigPaths,
78
+ options: {},
79
+ errors: [],
80
+ vueOptions: getDefaultCompilerOptions(),
104
81
  };
105
82
  }
106
83
  class CompilerOptionsResolver {
@@ -3,9 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.templateInlineTsAsts = void 0;
4
4
  exports.computedSfc = computedSfc;
5
5
  const alien_signals_1 = require("alien-signals");
6
- const parseCssClassNames_1 = require("../utils/parseCssClassNames");
7
- const parseCssImports_1 = require("../utils/parseCssImports");
8
- const parseCssVars_1 = require("../utils/parseCssVars");
9
6
  const signals_1 = require("../utils/signals");
10
7
  exports.templateInlineTsAsts = new WeakMap();
11
8
  function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
@@ -106,9 +103,17 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
106
103
  const getSrc = computedAttrValue('__src', base, getBlock);
107
104
  const getModule = computedAttrValue('__module', base, getBlock);
108
105
  const getScoped = (0, alien_signals_1.computed)(() => !!getBlock().scoped);
109
- const getImports = (0, signals_1.computedItems)(() => [...(0, parseCssImports_1.parseCssImports)(base.content)], (oldItem, newItem) => oldItem.text === newItem.text && oldItem.offset === newItem.offset);
110
- const getCssVars = (0, signals_1.computedItems)(() => [...(0, parseCssVars_1.parseCssVars)(base.content)], (oldItem, newItem) => oldItem.text === newItem.text && oldItem.offset === newItem.offset);
111
- const getClassNames = (0, signals_1.computedItems)(() => [...(0, parseCssClassNames_1.parseCssClassNames)(base.content)], (oldItem, newItem) => oldItem.text === newItem.text && oldItem.offset === newItem.offset);
106
+ const getIr = (0, alien_signals_1.computed)(() => {
107
+ for (const plugin of plugins) {
108
+ const ast = plugin.compileSFCStyle?.(base.lang, base.content);
109
+ if (ast) {
110
+ return ast;
111
+ }
112
+ }
113
+ });
114
+ const getImports = (0, signals_1.computedItems)(() => getIr()?.imports ?? [], (oldItem, newItem) => oldItem.text === newItem.text && oldItem.offset === newItem.offset);
115
+ const getBindings = (0, signals_1.computedItems)(() => getIr()?.bindings ?? [], (oldItem, newItem) => oldItem.text === newItem.text && oldItem.offset === newItem.offset);
116
+ const getClassNames = (0, signals_1.computedItems)(() => getIr()?.classNames ?? [], (oldItem, newItem) => oldItem.text === newItem.text && oldItem.offset === newItem.offset);
112
117
  return () => mergeObject(base, {
113
118
  get src() {
114
119
  return getSrc();
@@ -122,8 +127,8 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
122
127
  get imports() {
123
128
  return getImports();
124
129
  },
125
- get cssVars() {
126
- return getCssVars();
130
+ get bindings() {
131
+ return getBindings();
127
132
  },
128
133
  get classNames() {
129
134
  return getClassNames();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-core",
3
- "version": "3.0.5",
3
+ "version": "3.0.7-alpha.0",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -13,7 +13,7 @@
13
13
  "directory": "packages/language-core"
14
14
  },
15
15
  "dependencies": {
16
- "@volar/language-core": "2.4.22",
16
+ "@volar/language-core": "2.4.23",
17
17
  "@vue/compiler-dom": "^3.5.0",
18
18
  "@vue/compiler-vue2": "^2.7.16",
19
19
  "@vue/shared": "^3.5.0",
@@ -26,7 +26,7 @@
26
26
  "@types/node": "^22.10.4",
27
27
  "@types/path-browserify": "^1.0.1",
28
28
  "@types/picomatch": "^4.0.0",
29
- "@volar/typescript": "2.4.22",
29
+ "@volar/typescript": "2.4.23",
30
30
  "@vue/compiler-sfc": "^3.5.0"
31
31
  },
32
32
  "peerDependencies": {
@@ -37,5 +37,5 @@
37
37
  "optional": true
38
38
  }
39
39
  },
40
- "gitHead": "036b6b1882179d35586e16f2a5cba5150e5d18e6"
40
+ "gitHead": "a66f2330b5aa6f811f571159245c46af0c36c534"
41
41
  }
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=tenp.js.map
@@ -1,12 +0,0 @@
1
- import type * as ts from 'typescript';
2
- import type { TextRange } from '../types';
3
- export declare function parseBindingRanges(ts: typeof import('typescript'), ast: ts.SourceFile): {
4
- range: TextRange;
5
- moduleName?: string;
6
- isDefaultImport?: boolean;
7
- isNamespace?: boolean;
8
- }[];
9
- export declare function getClosestMultiLineCommentRange(ts: typeof import('typescript'), node: ts.Node, parents: ts.Node[], ast: ts.SourceFile): {
10
- start: number;
11
- end: number;
12
- } | undefined;
@@ -1,95 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseBindingRanges = parseBindingRanges;
4
- exports.getClosestMultiLineCommentRange = getClosestMultiLineCommentRange;
5
- const collectBindings_1 = require("../utils/collectBindings");
6
- const shared_1 = require("../utils/shared");
7
- function parseBindingRanges(ts, ast) {
8
- const bindings = [];
9
- ts.forEachChild(ast, node => {
10
- if (ts.isVariableStatement(node)) {
11
- for (const decl of node.declarationList.declarations) {
12
- const ranges = (0, collectBindings_1.collectBindingRanges)(ts, decl.name, ast);
13
- bindings.push(...ranges.map(range => ({ range })));
14
- }
15
- }
16
- else if (ts.isFunctionDeclaration(node)) {
17
- if (node.name && ts.isIdentifier(node.name)) {
18
- bindings.push({
19
- range: _getStartEnd(node.name),
20
- });
21
- }
22
- }
23
- else if (ts.isClassDeclaration(node)) {
24
- if (node.name) {
25
- bindings.push({
26
- range: _getStartEnd(node.name),
27
- });
28
- }
29
- }
30
- else if (ts.isEnumDeclaration(node)) {
31
- bindings.push({
32
- range: _getStartEnd(node.name),
33
- });
34
- }
35
- if (ts.isImportDeclaration(node)) {
36
- const moduleName = _getNodeText(node.moduleSpecifier).slice(1, -1);
37
- if (node.importClause && !node.importClause.isTypeOnly) {
38
- const { name, namedBindings } = node.importClause;
39
- if (name) {
40
- bindings.push({
41
- range: _getStartEnd(name),
42
- moduleName,
43
- isDefaultImport: true,
44
- });
45
- }
46
- if (namedBindings) {
47
- if (ts.isNamedImports(namedBindings)) {
48
- for (const element of namedBindings.elements) {
49
- if (element.isTypeOnly) {
50
- continue;
51
- }
52
- bindings.push({
53
- range: _getStartEnd(element.name),
54
- moduleName,
55
- isDefaultImport: element.propertyName?.text === 'default',
56
- });
57
- }
58
- }
59
- else {
60
- bindings.push({
61
- range: _getStartEnd(namedBindings.name),
62
- moduleName,
63
- isNamespace: true,
64
- });
65
- }
66
- }
67
- }
68
- }
69
- });
70
- return bindings;
71
- function _getStartEnd(node) {
72
- return (0, shared_1.getStartEnd)(ts, node, ast);
73
- }
74
- function _getNodeText(node) {
75
- return (0, shared_1.getNodeText)(ts, node, ast);
76
- }
77
- }
78
- function getClosestMultiLineCommentRange(ts, node, parents, ast) {
79
- for (let i = parents.length - 1; i >= 0; i--) {
80
- if (ts.isStatement(node)) {
81
- break;
82
- }
83
- node = parents[i];
84
- }
85
- const comment = ts.getLeadingCommentRanges(ast.text, node.pos)
86
- ?.reverse()
87
- .find(range => range.kind === 3);
88
- if (comment) {
89
- return {
90
- start: comment.pos,
91
- end: comment.end,
92
- };
93
- }
94
- }
95
- //# sourceMappingURL=utils.js.map
@@ -1,3 +0,0 @@
1
- import type { VueLanguagePlugin } from '../types';
2
- declare const plugin: VueLanguagePlugin;
3
- export default plugin;
@@ -1,57 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const parseSfc_1 = require("../utils/parseSfc");
4
- const plugin = ({ vueCompilerOptions }) => {
5
- return {
6
- version: 2.1,
7
- getLanguageId(fileName) {
8
- if (vueCompilerOptions.extensions.some(ext => fileName.endsWith(ext))) {
9
- return 'vue';
10
- }
11
- },
12
- isValidFile(_fileName, languageId) {
13
- return languageId === 'vue';
14
- },
15
- parseSFC2(_fileName, languageId, content) {
16
- if (languageId !== 'vue') {
17
- return;
18
- }
19
- return (0, parseSfc_1.parse)(content);
20
- },
21
- updateSFC(sfc, change) {
22
- const blocks = [
23
- sfc.descriptor.template,
24
- sfc.descriptor.script,
25
- sfc.descriptor.scriptSetup,
26
- ...sfc.descriptor.styles,
27
- ...sfc.descriptor.customBlocks,
28
- ].filter(block => !!block);
29
- const hitBlock = blocks.find(block => change.start >= block.loc.start.offset && change.end <= block.loc.end.offset);
30
- if (!hitBlock) {
31
- return;
32
- }
33
- const oldContent = hitBlock.content;
34
- const newContent = hitBlock.content = hitBlock.content.slice(0, change.start - hitBlock.loc.start.offset)
35
- + change.newText
36
- + hitBlock.content.slice(change.end - hitBlock.loc.start.offset);
37
- // #3449
38
- const endTagRegex = new RegExp(`</\\s*${hitBlock.type}\\s*>`);
39
- const insertedEndTag = endTagRegex.test(oldContent) !== endTagRegex.test(newContent);
40
- if (insertedEndTag) {
41
- return;
42
- }
43
- const lengthDiff = change.newText.length - (change.end - change.start);
44
- for (const block of blocks) {
45
- if (block.loc.start.offset > change.end) {
46
- block.loc.start.offset += lengthDiff;
47
- }
48
- if (block.loc.end.offset >= change.end) {
49
- block.loc.end.offset += lengthDiff;
50
- }
51
- }
52
- return sfc;
53
- },
54
- };
55
- };
56
- exports.default = plugin;
57
- //# sourceMappingURL=file-css.js.map
@@ -1,4 +0,0 @@
1
- export declare function parseCssClassNames(css: string): Generator<{
2
- offset: number;
3
- text: string;
4
- }, void, unknown>;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseCssClassNames = parseCssClassNames;
4
- const parseCssVars_1 = require("./parseCssVars");
5
- const cssClassNameReg = /(?=(\.[a-z_][-\w]*)[\s.,+~>:#)[{])/gi;
6
- const fragmentReg = /(?<={)[^{]*(?=(?<!\\);)/g;
7
- function* parseCssClassNames(css) {
8
- css = (0, parseCssVars_1.fillBlank)(css, parseCssVars_1.commentReg, fragmentReg);
9
- const matches = css.matchAll(cssClassNameReg);
10
- for (const match of matches) {
11
- const matchText = match[1];
12
- if (matchText) {
13
- yield { offset: match.index, text: matchText };
14
- }
15
- }
16
- }
17
- //# sourceMappingURL=parseCssClassNames.js.map
@@ -1,4 +0,0 @@
1
- export declare function parseCssImports(css: string): Generator<{
2
- text: string;
3
- offset: number;
4
- }, void, unknown>;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseCssImports = parseCssImports;
4
- const cssImportReg = /(?<=@import\s+url\()(["']?).*?\1(?=\))|(?<=@import\b\s*)(["']).*?\2/g;
5
- function* parseCssImports(css) {
6
- const matches = css.matchAll(cssImportReg);
7
- for (const match of matches) {
8
- let text = match[0];
9
- let offset = match.index;
10
- if (text.startsWith("'") || text.startsWith('"')) {
11
- text = text.slice(1, -1);
12
- offset += 1;
13
- }
14
- if (text) {
15
- yield { text, offset };
16
- }
17
- }
18
- }
19
- //# sourceMappingURL=parseCssImports.js.map
@@ -1,6 +0,0 @@
1
- export declare const commentReg: RegExp;
2
- export declare function parseCssVars(css: string): Generator<{
3
- offset: number;
4
- text: string;
5
- }, void, unknown>;
6
- export declare function fillBlank(css: string, ...regs: RegExp[]): string;
@@ -1,26 +0,0 @@
1
- "use strict";
2
- // https://github.com/vuejs/core/blob/main/packages/compiler-sfc/src/cssVars.ts#L47-L61
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.commentReg = void 0;
5
- exports.parseCssVars = parseCssVars;
6
- exports.fillBlank = fillBlank;
7
- const vBindCssVarReg = /\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([a-z_]\w*))\s*\)/gi;
8
- exports.commentReg = /(?<=\/\*)[\s\S]*?(?=\*\/)|(?<=\/\/)[\s\S]*?(?=\n)/g;
9
- function* parseCssVars(css) {
10
- css = fillBlank(css, exports.commentReg);
11
- const matchs = css.matchAll(vBindCssVarReg);
12
- for (const match of matchs) {
13
- const matchText = match.slice(1).find(t => t);
14
- if (matchText) {
15
- const offset = match.index + css.slice(match.index).indexOf(matchText);
16
- yield { offset, text: matchText };
17
- }
18
- }
19
- }
20
- function fillBlank(css, ...regs) {
21
- for (const reg of regs) {
22
- css = css.replace(reg, match => ' '.repeat(match.length));
23
- }
24
- return css;
25
- }
26
- //# sourceMappingURL=parseCssVars.js.map