@vue/compiler-sfc 3.3.2 → 3.3.3

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.
@@ -1142,7 +1142,8 @@ function processExp(exp, dir) {
1142
1142
  } else if (dir === "for") {
1143
1143
  const inMatch = exp.match(forAliasRE);
1144
1144
  if (inMatch) {
1145
- const [, LHS, RHS] = inMatch;
1145
+ let [, LHS, RHS] = inMatch;
1146
+ LHS = LHS.trim().replace(/^\(|\)$/g, "");
1146
1147
  return processExp(`(${LHS})=>{}`) + processExp(RHS);
1147
1148
  }
1148
1149
  }
@@ -18351,7 +18352,7 @@ function qualifiedNameToPath(node) {
18351
18352
  }
18352
18353
  function resolveGlobalScope(ctx) {
18353
18354
  if (ctx.options.globalTypeFiles) {
18354
- const fs = ctx.options.fs || (ts == null ? void 0 : ts.sys);
18355
+ const fs = resolveFS(ctx);
18355
18356
  if (!fs) {
18356
18357
  throw new Error("[vue/compiler-sfc] globalTypeFiles requires fs access.");
18357
18358
  }
@@ -18364,15 +18365,38 @@ let ts;
18364
18365
  function registerTS(_ts) {
18365
18366
  ts = _ts;
18366
18367
  }
18368
+ function resolveFS(ctx) {
18369
+ if (ctx.fs) {
18370
+ return ctx.fs;
18371
+ }
18372
+ const fs = ctx.options.fs || ts.sys;
18373
+ if (!fs) {
18374
+ return;
18375
+ }
18376
+ return ctx.fs = {
18377
+ fileExists(file) {
18378
+ if (file.endsWith(".vue.ts")) {
18379
+ file = file.replace(/\.ts$/, "");
18380
+ }
18381
+ return fs.fileExists(file);
18382
+ },
18383
+ readFile(file) {
18384
+ if (file.endsWith(".vue.ts")) {
18385
+ file = file.replace(/\.ts$/, "");
18386
+ }
18387
+ return fs.readFile(file);
18388
+ }
18389
+ };
18390
+ }
18367
18391
  function resolveTypeFromImport(ctx, node, name, scope) {
18368
18392
  const { source, imported } = scope.imports[name];
18369
18393
  const sourceScope = importSourceToScope(ctx, node, scope, source);
18370
18394
  return resolveTypeReference(ctx, node, sourceScope, imported, true);
18371
18395
  }
18372
18396
  function importSourceToScope(ctx, node, scope, source) {
18373
- const fs = ctx.options.fs || (ts == null ? void 0 : ts.sys);
18397
+ const fs = resolveFS(ctx);
18374
18398
  if (!fs) {
18375
- ctx.error(
18399
+ return ctx.error(
18376
18400
  `No fs option provided to \`compileScript\` in non-Node environment. File system access is required for resolving imported types.`,
18377
18401
  node,
18378
18402
  scope
@@ -18409,6 +18433,7 @@ function importSourceToScope(ctx, node, scope, source) {
18409
18433
  }
18410
18434
  }
18411
18435
  function resolveExt(filename, fs) {
18436
+ filename = filename.replace(/\.js$/, "");
18412
18437
  const tryResolve = (filename2) => {
18413
18438
  if (fs.fileExists(filename2))
18414
18439
  return filename2;
@@ -18471,7 +18496,11 @@ function resolveWithTS(containingFile, source, fs) {
18471
18496
  tsResolveCache
18472
18497
  );
18473
18498
  if (res.resolvedModule) {
18474
- return res.resolvedModule.resolvedFileName;
18499
+ let filename = res.resolvedModule.resolvedFileName;
18500
+ if (filename.endsWith(".vue.ts")) {
18501
+ filename = filename.replace(/\.ts$/, "");
18502
+ }
18503
+ return filename;
18475
18504
  }
18476
18505
  }
18477
18506
  function loadTSConfig(configPath, fs) {
@@ -18506,7 +18535,7 @@ function fileToScope(ctx, filename, asGlobal = false) {
18506
18535
  if (cached) {
18507
18536
  return cached;
18508
18537
  }
18509
- const fs = ctx.options.fs || (ts == null ? void 0 : ts.sys);
18538
+ const fs = resolveFS(ctx);
18510
18539
  const source = fs.readFile(filename) || "";
18511
18540
  const body = parseFile(filename, source, ctx.options.babelParserPlugins);
18512
18541
  const scope = new TypeScope(filename, source, 0, recordImports(body));
@@ -19037,6 +19066,20 @@ function resolveReturnType(ctx, arg, scope) {
19037
19066
  return resolved.returnType;
19038
19067
  }
19039
19068
  }
19069
+ function resolveUnionType(ctx, node, scope) {
19070
+ if (node.type === "TSTypeReference") {
19071
+ const resolved = resolveTypeReference(ctx, node, scope);
19072
+ if (resolved)
19073
+ node = resolved;
19074
+ }
19075
+ let types;
19076
+ if (node.type === "TSUnionType") {
19077
+ types = node.types.flatMap((node2) => resolveUnionType(ctx, node2, scope));
19078
+ } else {
19079
+ types = [node];
19080
+ }
19081
+ return types;
19082
+ }
19040
19083
 
19041
19084
  const DEFINE_MODEL = "defineModel";
19042
19085
  function processDefineModel(ctx, node, declId) {
@@ -19327,7 +19370,7 @@ function genDestructuredDefaultValue(ctx, key, inferredType) {
19327
19370
  if (defaultVal) {
19328
19371
  const value = ctx.getString(defaultVal);
19329
19372
  const unwrapped = unwrapTSNode(defaultVal);
19330
- if (inferredType && inferredType.length && !inferredType.includes(UNKNOWN_TYPE)) {
19373
+ if (inferredType && inferredType.length && !inferredType.includes("null")) {
19331
19374
  const valueType = inferValueType(unwrapped);
19332
19375
  if (valueType && !inferredType.includes(valueType)) {
19333
19376
  ctx.error(
@@ -19596,7 +19639,7 @@ function extractRuntimeEmits(ctx) {
19596
19639
  const emits = /* @__PURE__ */ new Set();
19597
19640
  const node = ctx.emitsTypeDecl;
19598
19641
  if (node.type === "TSFunctionType") {
19599
- extractEventNames(node.parameters[0], emits);
19642
+ extractEventNames(ctx, node.parameters[0], emits);
19600
19643
  return emits;
19601
19644
  }
19602
19645
  const { props, calls } = resolveTypeElements(ctx, node);
@@ -19613,22 +19656,18 @@ function extractRuntimeEmits(ctx) {
19613
19656
  );
19614
19657
  }
19615
19658
  for (const call of calls) {
19616
- extractEventNames(call.parameters[0], emits);
19659
+ extractEventNames(ctx, call.parameters[0], emits);
19617
19660
  }
19618
19661
  }
19619
19662
  return emits;
19620
19663
  }
19621
- function extractEventNames(eventName, emits) {
19664
+ function extractEventNames(ctx, eventName, emits) {
19622
19665
  if (eventName.type === "Identifier" && eventName.typeAnnotation && eventName.typeAnnotation.type === "TSTypeAnnotation") {
19623
- const typeNode = eventName.typeAnnotation.typeAnnotation;
19624
- if (typeNode.type === "TSLiteralType") {
19625
- if (typeNode.literal.type !== "UnaryExpression" && typeNode.literal.type !== "TemplateLiteral") {
19626
- emits.add(String(typeNode.literal.value));
19627
- }
19628
- } else if (typeNode.type === "TSUnionType") {
19629
- for (const t of typeNode.types) {
19630
- if (t.type === "TSLiteralType" && t.literal.type !== "UnaryExpression" && t.literal.type !== "TemplateLiteral") {
19631
- emits.add(String(t.literal.value));
19666
+ const types = resolveUnionType(ctx, eventName.typeAnnotation.typeAnnotation);
19667
+ for (const type of types) {
19668
+ if (type.type === "TSLiteralType") {
19669
+ if (type.literal.type !== "UnaryExpression" && type.literal.type !== "TemplateLiteral") {
19670
+ emits.add(String(type.literal.value));
19632
19671
  }
19633
19672
  }
19634
19673
  }
@@ -20531,6 +20570,7 @@ function canNeverBeRef(node, userReactiveImport) {
20531
20570
  }
20532
20571
  }
20533
20572
  function isStaticNode(node) {
20573
+ node = unwrapTSNode(node);
20534
20574
  switch (node.type) {
20535
20575
  case "UnaryExpression":
20536
20576
  return isStaticNode(node.argument);
@@ -20544,19 +20584,18 @@ function isStaticNode(node) {
20544
20584
  case "TemplateLiteral":
20545
20585
  return node.expressions.every((expr) => isStaticNode(expr));
20546
20586
  case "ParenthesizedExpression":
20547
- case "TSNonNullExpression":
20548
- case "TSAsExpression":
20549
- case "TSTypeAssertion":
20550
20587
  return isStaticNode(node.expression);
20551
- default:
20552
- if (isLiteralNode(node)) {
20553
- return true;
20554
- }
20555
- return false;
20588
+ case "StringLiteral":
20589
+ case "NumericLiteral":
20590
+ case "BooleanLiteral":
20591
+ case "NullLiteral":
20592
+ case "BigIntLiteral":
20593
+ return true;
20556
20594
  }
20595
+ return false;
20557
20596
  }
20558
20597
 
20559
- const version = "3.3.2";
20598
+ const version = "3.3.3";
20560
20599
  const walk = estreeWalker.walk;
20561
20600
 
20562
20601
  exports.babelParse = parser$2.parse;
@@ -394,6 +394,10 @@ export declare class ScriptCompileContext {
394
394
  * to be exposed on compiled script block for HMR cache busting
395
395
  */
396
396
  deps?: Set<string>;
397
+ /**
398
+ * cache for resolved fs
399
+ */
400
+ fs?: NonNullable<SFCScriptCompileOptions['fs']>;
397
401
  constructor(descriptor: SFCDescriptor, options: Partial<SFCScriptCompileOptions>);
398
402
  getString(node: Node, scriptSetup?: boolean): string;
399
403
  error(msg: string, node: Node, scope?: TypeScope): never;
@@ -414,7 +418,7 @@ export declare class ScriptCompileContext {
414
418
  * }
415
419
  * ```
416
420
  */
417
- export type SimpleTypeResolveContext = Pick<ScriptCompileContext, 'source' | 'filename' | 'error' | 'options'> & Partial<Pick<ScriptCompileContext, 'scope' | 'globalScopes' | 'deps'>> & {
421
+ export type SimpleTypeResolveContext = Pick<ScriptCompileContext, 'source' | 'filename' | 'error' | 'options'> & Partial<Pick<ScriptCompileContext, 'scope' | 'globalScopes' | 'deps' | 'fs'>> & {
418
422
  ast: Statement[];
419
423
  };
420
424
  export type TypeResolveContext = ScriptCompileContext | SimpleTypeResolveContext;
@@ -146,7 +146,7 @@ function normalizeStyle(value) {
146
146
  }
147
147
  const listDelimiterRE = /;(?![^(]*\))/g;
148
148
  const propertyDelimiterRE = /:([^]+)/;
149
- const styleCommentRE = new RegExp("\\/\\*.*?\\*\\/", "gs");
149
+ const styleCommentRE = /\/\*[^]*?\*\//g;
150
150
  function parseStringStyle(cssText) {
151
151
  const ret = {};
152
152
  cssText.replace(styleCommentRE, "").split(listDelimiterRE).forEach((item) => {
@@ -26963,7 +26963,8 @@ function processExp(exp, dir) {
26963
26963
  } else if (dir === "for") {
26964
26964
  const inMatch = exp.match(forAliasRE);
26965
26965
  if (inMatch) {
26966
- const [, LHS, RHS] = inMatch;
26966
+ let [, LHS, RHS] = inMatch;
26967
+ LHS = LHS.trim().replace(/^\(|\)$/g, "");
26967
26968
  return processExp(`(${LHS})=>{}`) + processExp(RHS);
26968
26969
  }
26969
26970
  }
@@ -48102,7 +48103,7 @@ function qualifiedNameToPath(node) {
48102
48103
  }
48103
48104
  function resolveGlobalScope(ctx) {
48104
48105
  if (ctx.options.globalTypeFiles) {
48105
- const fs = ctx.options.fs || (ts == null ? void 0 : ts.sys);
48106
+ const fs = resolveFS(ctx);
48106
48107
  if (!fs) {
48107
48108
  throw new Error("[vue/compiler-sfc] globalTypeFiles requires fs access.");
48108
48109
  }
@@ -48115,15 +48116,38 @@ let ts;
48115
48116
  function registerTS(_ts) {
48116
48117
  ts = _ts;
48117
48118
  }
48119
+ function resolveFS(ctx) {
48120
+ if (ctx.fs) {
48121
+ return ctx.fs;
48122
+ }
48123
+ const fs = ctx.options.fs || ts.sys;
48124
+ if (!fs) {
48125
+ return;
48126
+ }
48127
+ return ctx.fs = {
48128
+ fileExists(file) {
48129
+ if (file.endsWith(".vue.ts")) {
48130
+ file = file.replace(/\.ts$/, "");
48131
+ }
48132
+ return fs.fileExists(file);
48133
+ },
48134
+ readFile(file) {
48135
+ if (file.endsWith(".vue.ts")) {
48136
+ file = file.replace(/\.ts$/, "");
48137
+ }
48138
+ return fs.readFile(file);
48139
+ }
48140
+ };
48141
+ }
48118
48142
  function resolveTypeFromImport(ctx, node, name, scope) {
48119
48143
  const { source, imported } = scope.imports[name];
48120
48144
  const sourceScope = importSourceToScope(ctx, node, scope, source);
48121
48145
  return resolveTypeReference(ctx, node, sourceScope, imported, true);
48122
48146
  }
48123
48147
  function importSourceToScope(ctx, node, scope, source) {
48124
- const fs = ctx.options.fs || (ts == null ? void 0 : ts.sys);
48148
+ const fs = resolveFS(ctx);
48125
48149
  if (!fs) {
48126
- ctx.error(
48150
+ return ctx.error(
48127
48151
  `No fs option provided to \`compileScript\` in non-Node environment. File system access is required for resolving imported types.`,
48128
48152
  node,
48129
48153
  scope
@@ -48167,6 +48191,7 @@ function importSourceToScope(ctx, node, scope, source) {
48167
48191
  }
48168
48192
  }
48169
48193
  function resolveExt(filename, fs) {
48194
+ filename = filename.replace(/\.js$/, "");
48170
48195
  const tryResolve = (filename2) => {
48171
48196
  if (fs.fileExists(filename2))
48172
48197
  return filename2;
@@ -48192,7 +48217,7 @@ function fileToScope(ctx, filename, asGlobal = false) {
48192
48217
  if (cached) {
48193
48218
  return cached;
48194
48219
  }
48195
- const fs = ctx.options.fs || (ts == null ? void 0 : ts.sys);
48220
+ const fs = resolveFS(ctx);
48196
48221
  const source = fs.readFile(filename) || "";
48197
48222
  const body = parseFile(filename, source, ctx.options.babelParserPlugins);
48198
48223
  const scope = new TypeScope(filename, source, 0, recordImports(body));
@@ -48723,6 +48748,20 @@ function resolveReturnType(ctx, arg, scope) {
48723
48748
  return resolved.returnType;
48724
48749
  }
48725
48750
  }
48751
+ function resolveUnionType(ctx, node, scope) {
48752
+ if (node.type === "TSTypeReference") {
48753
+ const resolved = resolveTypeReference(ctx, node, scope);
48754
+ if (resolved)
48755
+ node = resolved;
48756
+ }
48757
+ let types;
48758
+ if (node.type === "TSUnionType") {
48759
+ types = node.types.flatMap((node2) => resolveUnionType(ctx, node2, scope));
48760
+ } else {
48761
+ types = [node];
48762
+ }
48763
+ return types;
48764
+ }
48726
48765
 
48727
48766
  const DEFINE_MODEL = "defineModel";
48728
48767
  function processDefineModel(ctx, node, declId) {
@@ -49013,7 +49052,7 @@ function genDestructuredDefaultValue(ctx, key, inferredType) {
49013
49052
  if (defaultVal) {
49014
49053
  const value = ctx.getString(defaultVal);
49015
49054
  const unwrapped = unwrapTSNode(defaultVal);
49016
- if (inferredType && inferredType.length && !inferredType.includes(UNKNOWN_TYPE)) {
49055
+ if (inferredType && inferredType.length && !inferredType.includes("null")) {
49017
49056
  const valueType = inferValueType(unwrapped);
49018
49057
  if (valueType && !inferredType.includes(valueType)) {
49019
49058
  ctx.error(
@@ -49282,7 +49321,7 @@ function extractRuntimeEmits(ctx) {
49282
49321
  const emits = /* @__PURE__ */ new Set();
49283
49322
  const node = ctx.emitsTypeDecl;
49284
49323
  if (node.type === "TSFunctionType") {
49285
- extractEventNames(node.parameters[0], emits);
49324
+ extractEventNames(ctx, node.parameters[0], emits);
49286
49325
  return emits;
49287
49326
  }
49288
49327
  const { props, calls } = resolveTypeElements(ctx, node);
@@ -49299,22 +49338,18 @@ function extractRuntimeEmits(ctx) {
49299
49338
  );
49300
49339
  }
49301
49340
  for (const call of calls) {
49302
- extractEventNames(call.parameters[0], emits);
49341
+ extractEventNames(ctx, call.parameters[0], emits);
49303
49342
  }
49304
49343
  }
49305
49344
  return emits;
49306
49345
  }
49307
- function extractEventNames(eventName, emits) {
49346
+ function extractEventNames(ctx, eventName, emits) {
49308
49347
  if (eventName.type === "Identifier" && eventName.typeAnnotation && eventName.typeAnnotation.type === "TSTypeAnnotation") {
49309
- const typeNode = eventName.typeAnnotation.typeAnnotation;
49310
- if (typeNode.type === "TSLiteralType") {
49311
- if (typeNode.literal.type !== "UnaryExpression" && typeNode.literal.type !== "TemplateLiteral") {
49312
- emits.add(String(typeNode.literal.value));
49313
- }
49314
- } else if (typeNode.type === "TSUnionType") {
49315
- for (const t of typeNode.types) {
49316
- if (t.type === "TSLiteralType" && t.literal.type !== "UnaryExpression" && t.literal.type !== "TemplateLiteral") {
49317
- emits.add(String(t.literal.value));
49348
+ const types = resolveUnionType(ctx, eventName.typeAnnotation.typeAnnotation);
49349
+ for (const type of types) {
49350
+ if (type.type === "TSLiteralType") {
49351
+ if (type.literal.type !== "UnaryExpression" && type.literal.type !== "TemplateLiteral") {
49352
+ emits.add(String(type.literal.value));
49318
49353
  }
49319
49354
  }
49320
49355
  }
@@ -50231,6 +50266,7 @@ function canNeverBeRef(node, userReactiveImport) {
50231
50266
  }
50232
50267
  }
50233
50268
  function isStaticNode(node) {
50269
+ node = unwrapTSNode(node);
50234
50270
  switch (node.type) {
50235
50271
  case "UnaryExpression":
50236
50272
  return isStaticNode(node.argument);
@@ -50244,19 +50280,18 @@ function isStaticNode(node) {
50244
50280
  case "TemplateLiteral":
50245
50281
  return node.expressions.every((expr) => isStaticNode(expr));
50246
50282
  case "ParenthesizedExpression":
50247
- case "TSNonNullExpression":
50248
- case "TSAsExpression":
50249
- case "TSTypeAssertion":
50250
50283
  return isStaticNode(node.expression);
50251
- default:
50252
- if (isLiteralNode(node)) {
50253
- return true;
50254
- }
50255
- return false;
50284
+ case "StringLiteral":
50285
+ case "NumericLiteral":
50286
+ case "BooleanLiteral":
50287
+ case "NullLiteral":
50288
+ case "BigIntLiteral":
50289
+ return true;
50256
50290
  }
50291
+ return false;
50257
50292
  }
50258
50293
 
50259
- const version = "3.3.2";
50294
+ const version = "3.3.3";
50260
50295
  const walk = walk$1;
50261
50296
 
50262
50297
  export { MagicString, parse_1$1 as babelParse, compileScript, compileStyle, compileStyleAsync, compileTemplate, extractIdentifiers, generateCodeFrame, inferRuntimeType, invalidateTypeCache, isInDestructureAssignment, isStaticProperty, parse$7 as parse, parseCache, registerTS, resolveTypeElements, rewriteDefault, rewriteDefaultAST, shouldTransform as shouldTransformRef, transform as transformRef, transformAST as transformRefAST, version, walk, walkIdentifiers };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/compiler-sfc",
3
- "version": "3.3.2",
3
+ "version": "3.3.3",
4
4
  "description": "@vue/compiler-sfc",
5
5
  "main": "dist/compiler-sfc.cjs.js",
6
6
  "module": "dist/compiler-sfc.esm-browser.js",
@@ -33,11 +33,11 @@
33
33
  "homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-sfc#readme",
34
34
  "dependencies": {
35
35
  "@babel/parser": "^7.20.15",
36
- "@vue/compiler-core": "3.3.2",
37
- "@vue/compiler-dom": "3.3.2",
38
- "@vue/compiler-ssr": "3.3.2",
39
- "@vue/reactivity-transform": "3.3.2",
40
- "@vue/shared": "3.3.2",
36
+ "@vue/compiler-core": "3.3.3",
37
+ "@vue/compiler-dom": "3.3.3",
38
+ "@vue/compiler-ssr": "3.3.3",
39
+ "@vue/reactivity-transform": "3.3.3",
40
+ "@vue/shared": "3.3.3",
41
41
  "estree-walker": "^2.0.2",
42
42
  "magic-string": "^0.30.0",
43
43
  "postcss": "^8.1.10",