@vue/compiler-sfc 3.6.0-alpha.1 → 3.6.0-alpha.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.
- package/dist/compiler-sfc.cjs.js +226 -79
- package/dist/compiler-sfc.d.ts +1 -1
- package/dist/compiler-sfc.esm-browser.js +985 -474
- package/package.json +11 -11
package/dist/compiler-sfc.cjs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vue/compiler-sfc v3.6.0-alpha.
|
|
2
|
+
* @vue/compiler-sfc v3.6.0-alpha.3
|
|
3
3
|
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
4
4
|
* @license MIT
|
|
5
5
|
**/
|
|
@@ -142,7 +142,7 @@ function genCssVarsFromList(vars, id, isProd, isSSR = false) {
|
|
|
142
142
|
}
|
|
143
143
|
function genVarName(id, raw, isProd, isSSR = false) {
|
|
144
144
|
if (isProd) {
|
|
145
|
-
return hash(id + raw);
|
|
145
|
+
return hash(id + raw).replace(/^\d/, (r) => `v${r}`);
|
|
146
146
|
} else {
|
|
147
147
|
return `${id}-${shared.getEscapedCssVarName(raw, isSSR)}`;
|
|
148
148
|
}
|
|
@@ -1705,8 +1705,8 @@ function createCache(max = 500) {
|
|
|
1705
1705
|
return new LRUCache({ max });
|
|
1706
1706
|
}
|
|
1707
1707
|
|
|
1708
|
-
function
|
|
1709
|
-
return resolveTemplateUsedIdentifiers(sfc).has(
|
|
1708
|
+
function isUsedInTemplate(identifier, sfc) {
|
|
1709
|
+
return resolveTemplateUsedIdentifiers(sfc).has(identifier);
|
|
1710
1710
|
}
|
|
1711
1711
|
const templateUsageCheckCache = createCache();
|
|
1712
1712
|
function resolveTemplateUsedIdentifiers(sfc) {
|
|
@@ -2031,7 +2031,7 @@ function hmrShouldReload(prevImports, next) {
|
|
|
2031
2031
|
return false;
|
|
2032
2032
|
}
|
|
2033
2033
|
for (const key in prevImports) {
|
|
2034
|
-
if (!prevImports[key].isUsedInTemplate &&
|
|
2034
|
+
if (!prevImports[key].isUsedInTemplate && isUsedInTemplate(key, next)) {
|
|
2035
2035
|
return true;
|
|
2036
2036
|
}
|
|
2037
2037
|
}
|
|
@@ -2062,7 +2062,7 @@ function isRelativeUrl(url) {
|
|
|
2062
2062
|
const firstChar = url.charAt(0);
|
|
2063
2063
|
return firstChar === "." || firstChar === "~" || firstChar === "@";
|
|
2064
2064
|
}
|
|
2065
|
-
const externalRE = /^(https?:)?\/\//;
|
|
2065
|
+
const externalRE = /^(?:https?:)?\/\//;
|
|
2066
2066
|
function isExternalUrl(url) {
|
|
2067
2067
|
return externalRE.test(url);
|
|
2068
2068
|
}
|
|
@@ -2221,7 +2221,7 @@ const transformSrcset = (node, context, options = defaultAssetUrlOptions) => {
|
|
|
2221
2221
|
}
|
|
2222
2222
|
}
|
|
2223
2223
|
const shouldProcessUrl = (url) => {
|
|
2224
|
-
return !isExternalUrl(url) && !isDataUrl(url) && (options.includeAbsolute || isRelativeUrl(url));
|
|
2224
|
+
return url && !isExternalUrl(url) && !isDataUrl(url) && (options.includeAbsolute || isRelativeUrl(url));
|
|
2225
2225
|
};
|
|
2226
2226
|
if (!imageCandidates.some(({ url }) => shouldProcessUrl(url))) {
|
|
2227
2227
|
return;
|
|
@@ -8001,8 +8001,9 @@ function requireDist () {
|
|
|
8001
8001
|
var distExports = /*@__PURE__*/ requireDist();
|
|
8002
8002
|
var selectorParser = /*@__PURE__*/getDefaultExportFromCjs(distExports);
|
|
8003
8003
|
|
|
8004
|
-
const animationNameRE = /^(
|
|
8005
|
-
const animationRE = /^(
|
|
8004
|
+
const animationNameRE = /^(?:-\w+-)?animation-name$/;
|
|
8005
|
+
const animationRE = /^(?:-\w+-)?animation$/;
|
|
8006
|
+
const keyframesRE = /^(?:-\w+-)?keyframes$/;
|
|
8006
8007
|
const scopedPlugin = (id = "") => {
|
|
8007
8008
|
const keyframes = /* @__PURE__ */ Object.create(null);
|
|
8008
8009
|
const shortId = id.replace(/^data-v-/, "");
|
|
@@ -8012,7 +8013,7 @@ const scopedPlugin = (id = "") => {
|
|
|
8012
8013
|
processRule(id, rule);
|
|
8013
8014
|
},
|
|
8014
8015
|
AtRule(node) {
|
|
8015
|
-
if (
|
|
8016
|
+
if (keyframesRE.test(node.name) && !node.params.endsWith(`-${shortId}`)) {
|
|
8016
8017
|
keyframes[node.params] = node.params = node.params + "-" + shortId;
|
|
8017
8018
|
}
|
|
8018
8019
|
},
|
|
@@ -8041,7 +8042,7 @@ const scopedPlugin = (id = "") => {
|
|
|
8041
8042
|
};
|
|
8042
8043
|
const processedRules = /* @__PURE__ */ new WeakSet();
|
|
8043
8044
|
function processRule(id, rule) {
|
|
8044
|
-
if (processedRules.has(rule) || rule.parent && rule.parent.type === "atrule" &&
|
|
8045
|
+
if (processedRules.has(rule) || rule.parent && rule.parent.type === "atrule" && keyframesRE.test(rule.parent.name)) {
|
|
8045
8046
|
return;
|
|
8046
8047
|
}
|
|
8047
8048
|
processedRules.add(rule);
|
|
@@ -16232,6 +16233,9 @@ function getImportedName(specifier) {
|
|
|
16232
16233
|
function getId(node) {
|
|
16233
16234
|
return node.type === "Identifier" ? node.name : node.type === "StringLiteral" ? node.value : null;
|
|
16234
16235
|
}
|
|
16236
|
+
function getStringLiteralKey(node) {
|
|
16237
|
+
return node.computed ? node.key.type === "TemplateLiteral" && !node.key.expressions.length ? node.key.quasis.map((q) => q.value.cooked).join("") : null : node.key.type === "Identifier" ? node.key.name : node.key.type === "StringLiteral" ? node.key.value : node.key.type === "NumericLiteral" ? String(node.key.value) : null;
|
|
16238
|
+
}
|
|
16235
16239
|
const identity = (str) => str;
|
|
16236
16240
|
const fileNameLowerCaseRegExp = /[^\u0130\u0131\u00DFa-z0-9\\/:\-_\. ]+/g;
|
|
16237
16241
|
const toLowerCase = (str) => str.toLowerCase();
|
|
@@ -16251,6 +16255,8 @@ const propNameEscapeSymbolsRE = /[ !"#$%&'()*+,./:;<=>?@[\\\]^`{|}~\-]/;
|
|
|
16251
16255
|
function getEscapedPropName(key) {
|
|
16252
16256
|
return propNameEscapeSymbolsRE.test(key) ? JSON.stringify(key) : key;
|
|
16253
16257
|
}
|
|
16258
|
+
const isJS = (...langs) => langs.some((lang) => lang === "js" || lang === "jsx");
|
|
16259
|
+
const isTS = (...langs) => langs.some((lang) => lang === "ts" || lang === "tsx");
|
|
16254
16260
|
|
|
16255
16261
|
function analyzeScriptBindings(ast) {
|
|
16256
16262
|
for (const node of ast) {
|
|
@@ -16351,8 +16357,8 @@ class ScriptCompileContext {
|
|
|
16351
16357
|
const { script, scriptSetup } = descriptor;
|
|
16352
16358
|
const scriptLang = script && script.lang;
|
|
16353
16359
|
const scriptSetupLang = scriptSetup && scriptSetup.lang;
|
|
16354
|
-
this.isJS = scriptLang
|
|
16355
|
-
this.isTS = scriptLang
|
|
16360
|
+
this.isJS = isJS(scriptLang, scriptSetupLang);
|
|
16361
|
+
this.isTS = isTS(scriptLang, scriptSetupLang);
|
|
16356
16362
|
const customElement = options.customElement;
|
|
16357
16363
|
const filename = this.descriptor.filename;
|
|
16358
16364
|
if (customElement) {
|
|
@@ -16531,9 +16537,6 @@ const normalScriptDefaultVar = `__default__`;
|
|
|
16531
16537
|
function processNormalScript(ctx, scopeId) {
|
|
16532
16538
|
var _a;
|
|
16533
16539
|
const script = ctx.descriptor.script;
|
|
16534
|
-
if (script.lang && !ctx.isJS && !ctx.isTS) {
|
|
16535
|
-
return script;
|
|
16536
|
-
}
|
|
16537
16540
|
try {
|
|
16538
16541
|
let content = script.content;
|
|
16539
16542
|
let map = script.map;
|
|
@@ -16978,21 +16981,35 @@ const parseClass = (glob, position) => {
|
|
|
16978
16981
|
/**
|
|
16979
16982
|
* Un-escape a string that has been escaped with {@link escape}.
|
|
16980
16983
|
*
|
|
16981
|
-
* If the {@link windowsPathsNoEscape} option is used, then
|
|
16982
|
-
* escapes are removed, but not backslash escapes.
|
|
16983
|
-
*
|
|
16984
|
-
*
|
|
16984
|
+
* If the {@link MinimatchOptions.windowsPathsNoEscape} option is used, then
|
|
16985
|
+
* square-bracket escapes are removed, but not backslash escapes.
|
|
16986
|
+
*
|
|
16987
|
+
* For example, it will turn the string `'[*]'` into `*`, but it will not
|
|
16988
|
+
* turn `'\\*'` into `'*'`, because `\` is a path separator in
|
|
16989
|
+
* `windowsPathsNoEscape` mode.
|
|
16985
16990
|
*
|
|
16986
|
-
* When `windowsPathsNoEscape` is not set, then both
|
|
16991
|
+
* When `windowsPathsNoEscape` is not set, then both square-bracket escapes and
|
|
16987
16992
|
* backslash escapes are removed.
|
|
16988
16993
|
*
|
|
16989
16994
|
* Slashes (and backslashes in `windowsPathsNoEscape` mode) cannot be escaped
|
|
16990
16995
|
* or unescaped.
|
|
16996
|
+
*
|
|
16997
|
+
* When `magicalBraces` is not set, escapes of braces (`{` and `}`) will not be
|
|
16998
|
+
* unescaped.
|
|
16991
16999
|
*/
|
|
16992
|
-
const unescape = (s, { windowsPathsNoEscape = false, } = {}) => {
|
|
17000
|
+
const unescape = (s, { windowsPathsNoEscape = false, magicalBraces = true, } = {}) => {
|
|
17001
|
+
if (magicalBraces) {
|
|
17002
|
+
return windowsPathsNoEscape
|
|
17003
|
+
? s.replace(/\[([^\/\\])\]/g, '$1')
|
|
17004
|
+
: s
|
|
17005
|
+
.replace(/((?!\\).|^)\[([^\/\\])\]/g, '$1$2')
|
|
17006
|
+
.replace(/\\([^\/])/g, '$1');
|
|
17007
|
+
}
|
|
16993
17008
|
return windowsPathsNoEscape
|
|
16994
|
-
? s.replace(/\[([^\/\\])\]/g, '$1')
|
|
16995
|
-
: s
|
|
17009
|
+
? s.replace(/\[([^\/\\{}])\]/g, '$1')
|
|
17010
|
+
: s
|
|
17011
|
+
.replace(/((?!\\).|^)\[([^\/\\{}])\]/g, '$1$2')
|
|
17012
|
+
.replace(/\\([^\/{}])/g, '$1');
|
|
16996
17013
|
};
|
|
16997
17014
|
|
|
16998
17015
|
// parse a single path portion
|
|
@@ -17407,7 +17424,9 @@ class AST {
|
|
|
17407
17424
|
if (this.#root === this)
|
|
17408
17425
|
this.#fillNegs();
|
|
17409
17426
|
if (!this.type) {
|
|
17410
|
-
const noEmpty = this.isStart() &&
|
|
17427
|
+
const noEmpty = this.isStart() &&
|
|
17428
|
+
this.isEnd() &&
|
|
17429
|
+
!this.#parts.some(s => typeof s !== 'string');
|
|
17411
17430
|
const src = this.#parts
|
|
17412
17431
|
.map(p => {
|
|
17413
17432
|
const [re, _, hasMagic, uflag] = typeof p === 'string'
|
|
@@ -17563,10 +17582,7 @@ class AST {
|
|
|
17563
17582
|
}
|
|
17564
17583
|
}
|
|
17565
17584
|
if (c === '*') {
|
|
17566
|
-
|
|
17567
|
-
re += starNoEmpty;
|
|
17568
|
-
else
|
|
17569
|
-
re += star$1;
|
|
17585
|
+
re += noEmpty && glob === '*' ? starNoEmpty : star$1;
|
|
17570
17586
|
hasMagic = true;
|
|
17571
17587
|
continue;
|
|
17572
17588
|
}
|
|
@@ -17584,16 +17600,24 @@ class AST {
|
|
|
17584
17600
|
/**
|
|
17585
17601
|
* Escape all magic characters in a glob pattern.
|
|
17586
17602
|
*
|
|
17587
|
-
* If the {@link
|
|
17603
|
+
* If the {@link MinimatchOptions.windowsPathsNoEscape}
|
|
17588
17604
|
* option is used, then characters are escaped by wrapping in `[]`, because
|
|
17589
17605
|
* a magic character wrapped in a character class can only be satisfied by
|
|
17590
17606
|
* that exact character. In this mode, `\` is _not_ escaped, because it is
|
|
17591
17607
|
* not interpreted as a magic character, but instead as a path separator.
|
|
17608
|
+
*
|
|
17609
|
+
* If the {@link MinimatchOptions.magicalBraces} option is used,
|
|
17610
|
+
* then braces (`{` and `}`) will be escaped.
|
|
17592
17611
|
*/
|
|
17593
|
-
const escape = (s, { windowsPathsNoEscape = false, } = {}) => {
|
|
17612
|
+
const escape = (s, { windowsPathsNoEscape = false, magicalBraces = false, } = {}) => {
|
|
17594
17613
|
// don't need to escape +@! because we escape the parens
|
|
17595
17614
|
// that make those magic, and escaping ! as [!] isn't valid,
|
|
17596
17615
|
// because [!]] is a valid glob class meaning not ']'.
|
|
17616
|
+
if (magicalBraces) {
|
|
17617
|
+
return windowsPathsNoEscape
|
|
17618
|
+
? s.replace(/[?*()[\]{}]/g, '[$&]')
|
|
17619
|
+
: s.replace(/[?*()[\]\\{}]/g, '\\$&');
|
|
17620
|
+
}
|
|
17597
17621
|
return windowsPathsNoEscape
|
|
17598
17622
|
? s.replace(/[?*()[\]]/g, '[$&]')
|
|
17599
17623
|
: s.replace(/[?*()[\]\\]/g, '\\$&');
|
|
@@ -18227,7 +18251,7 @@ class Minimatch {
|
|
|
18227
18251
|
}
|
|
18228
18252
|
}
|
|
18229
18253
|
// resolve and reduce . and .. portions in the file as well.
|
|
18230
|
-
//
|
|
18254
|
+
// don't need to do the second phase, because it's only one string[]
|
|
18231
18255
|
const { optimizationLevel = 1 } = this.options;
|
|
18232
18256
|
if (optimizationLevel >= 2) {
|
|
18233
18257
|
file = this.levelTwoFileOptimize(file);
|
|
@@ -18480,14 +18504,25 @@ class Minimatch {
|
|
|
18480
18504
|
}
|
|
18481
18505
|
}
|
|
18482
18506
|
else if (next === undefined) {
|
|
18483
|
-
pp[i - 1] = prev + '(
|
|
18507
|
+
pp[i - 1] = prev + '(?:\\/|\\/' + twoStar + ')?';
|
|
18484
18508
|
}
|
|
18485
18509
|
else if (next !== GLOBSTAR) {
|
|
18486
18510
|
pp[i - 1] = prev + '(?:\\/|\\/' + twoStar + '\\/)' + next;
|
|
18487
18511
|
pp[i + 1] = GLOBSTAR;
|
|
18488
18512
|
}
|
|
18489
18513
|
});
|
|
18490
|
-
|
|
18514
|
+
const filtered = pp.filter(p => p !== GLOBSTAR);
|
|
18515
|
+
// For partial matches, we need to make the pattern match
|
|
18516
|
+
// any prefix of the full path. We do this by generating
|
|
18517
|
+
// alternative patterns that match progressively longer prefixes.
|
|
18518
|
+
if (this.partial && filtered.length >= 1) {
|
|
18519
|
+
const prefixes = [];
|
|
18520
|
+
for (let i = 1; i <= filtered.length; i++) {
|
|
18521
|
+
prefixes.push(filtered.slice(0, i).join('/'));
|
|
18522
|
+
}
|
|
18523
|
+
return '(?:' + prefixes.join('|') + ')';
|
|
18524
|
+
}
|
|
18525
|
+
return filtered.join('/');
|
|
18491
18526
|
})
|
|
18492
18527
|
.join('|');
|
|
18493
18528
|
// need to wrap in parens if we had more than one thing with |,
|
|
@@ -18496,6 +18531,10 @@ class Minimatch {
|
|
|
18496
18531
|
// must match entire pattern
|
|
18497
18532
|
// ending in a * or ** will make it less strict.
|
|
18498
18533
|
re = '^' + open + re + close + '$';
|
|
18534
|
+
// In partial mode, '/' should always match as it's a valid prefix for any pattern
|
|
18535
|
+
if (this.partial) {
|
|
18536
|
+
re = '^(?:\\/|' + open + re.slice(1, -1) + close + ')$';
|
|
18537
|
+
}
|
|
18499
18538
|
// can match anything, as long as it's not this.
|
|
18500
18539
|
if (this.negate)
|
|
18501
18540
|
re = '^(?!' + re + ').+$';
|
|
@@ -18766,13 +18805,9 @@ function typeElementsToMap(ctx, elements, scope = ctxToScope(ctx), typeParameter
|
|
|
18766
18805
|
Object.assign(scope.types, typeParameters);
|
|
18767
18806
|
}
|
|
18768
18807
|
e._ownerScope = scope;
|
|
18769
|
-
const name =
|
|
18770
|
-
if (name
|
|
18808
|
+
const name = getStringLiteralKey(e);
|
|
18809
|
+
if (name !== null) {
|
|
18771
18810
|
res.props[name] = e;
|
|
18772
|
-
} else if (e.key.type === "TemplateLiteral") {
|
|
18773
|
-
for (const key of resolveTemplateKeys(ctx, e.key, scope)) {
|
|
18774
|
-
res.props[key] = e;
|
|
18775
|
-
}
|
|
18776
18811
|
} else {
|
|
18777
18812
|
ctx.error(
|
|
18778
18813
|
`Unsupported computed key in type referenced by a macro`,
|
|
@@ -19171,7 +19206,7 @@ function registerTS(_loadTS) {
|
|
|
19171
19206
|
} catch (err) {
|
|
19172
19207
|
if (typeof err.message === "string" && err.message.includes("Cannot find module")) {
|
|
19173
19208
|
throw new Error(
|
|
19174
|
-
'Failed to load TypeScript, which is required for resolving imported types. Please make sure "
|
|
19209
|
+
'Failed to load TypeScript, which is required for resolving imported types. Please make sure "TypeScript" is installed as a project dependency.'
|
|
19175
19210
|
);
|
|
19176
19211
|
} else {
|
|
19177
19212
|
throw new Error(
|
|
@@ -19241,7 +19276,7 @@ function importSourceToScope(ctx, node, scope, source) {
|
|
|
19241
19276
|
if (loadTS) ts = loadTS();
|
|
19242
19277
|
if (!ts) {
|
|
19243
19278
|
return ctx.error(
|
|
19244
|
-
`Failed to resolve import source ${JSON.stringify(source)}.
|
|
19279
|
+
`Failed to resolve import source ${JSON.stringify(source)}. TypeScript is required as a peer dep for vue in order to support resolving types from module imports.`,
|
|
19245
19280
|
node,
|
|
19246
19281
|
scope
|
|
19247
19282
|
);
|
|
@@ -19292,14 +19327,19 @@ function resolveWithTS(containingFile, source, ts2, fs) {
|
|
|
19292
19327
|
if (configs.length === 1) {
|
|
19293
19328
|
matchedConfig = configs[0];
|
|
19294
19329
|
} else {
|
|
19330
|
+
const [major, minor] = ts2.versionMajorMinor.split(".").map(Number);
|
|
19331
|
+
const getPattern = (base, p) => {
|
|
19332
|
+
const supportsConfigDir = major > 5 || major === 5 && minor >= 5;
|
|
19333
|
+
return p.startsWith("${configDir}") && supportsConfigDir ? normalizePath(p.replace("${configDir}", path$1.dirname(configPath))) : joinPaths(base, p);
|
|
19334
|
+
};
|
|
19295
19335
|
for (const c of configs) {
|
|
19296
19336
|
const base = normalizePath(
|
|
19297
19337
|
c.config.options.pathsBasePath || path$1.dirname(c.config.options.configFilePath)
|
|
19298
19338
|
);
|
|
19299
19339
|
const included = (_a = c.config.raw) == null ? void 0 : _a.include;
|
|
19300
19340
|
const excluded = (_b = c.config.raw) == null ? void 0 : _b.exclude;
|
|
19301
|
-
if (!included && (!base || containingFile.startsWith(base)) || (included == null ? void 0 : included.some((p) => minimatch(containingFile,
|
|
19302
|
-
if (excluded && excluded.some((p) => minimatch(containingFile,
|
|
19341
|
+
if (!included && (!base || containingFile.startsWith(base)) || (included == null ? void 0 : included.some((p) => minimatch(containingFile, getPattern(base, p))))) {
|
|
19342
|
+
if (excluded && excluded.some((p) => minimatch(containingFile, getPattern(base, p)))) {
|
|
19303
19343
|
continue;
|
|
19304
19344
|
}
|
|
19305
19345
|
matchedConfig = c;
|
|
@@ -19473,7 +19513,11 @@ function recordTypes(ctx, body, scope, asGlobal = false) {
|
|
|
19473
19513
|
}
|
|
19474
19514
|
} else if (stmt.type === "TSModuleDeclaration" && stmt.global) {
|
|
19475
19515
|
for (const s of stmt.body.body) {
|
|
19476
|
-
|
|
19516
|
+
if (s.type === "ExportNamedDeclaration" && s.declaration) {
|
|
19517
|
+
recordType(s.declaration, types, declares);
|
|
19518
|
+
} else {
|
|
19519
|
+
recordType(s, types, declares);
|
|
19520
|
+
}
|
|
19477
19521
|
}
|
|
19478
19522
|
}
|
|
19479
19523
|
} else {
|
|
@@ -19647,7 +19691,10 @@ function recordImport(node, imports) {
|
|
|
19647
19691
|
};
|
|
19648
19692
|
}
|
|
19649
19693
|
}
|
|
19650
|
-
function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx), isKeyOf = false) {
|
|
19694
|
+
function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx), isKeyOf = false, typeParameters) {
|
|
19695
|
+
if (node.leadingComments && node.leadingComments.some((c) => c.value.includes("@vue-ignore"))) {
|
|
19696
|
+
return [UNKNOWN_TYPE];
|
|
19697
|
+
}
|
|
19651
19698
|
try {
|
|
19652
19699
|
switch (node.type) {
|
|
19653
19700
|
case "TSStringKeyword":
|
|
@@ -19720,12 +19767,38 @@ function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx)
|
|
|
19720
19767
|
case "TSTypeReference": {
|
|
19721
19768
|
const resolved = resolveTypeReference(ctx, node, scope);
|
|
19722
19769
|
if (resolved) {
|
|
19723
|
-
if (resolved.type === "TSTypeAliasDeclaration"
|
|
19724
|
-
|
|
19770
|
+
if (resolved.type === "TSTypeAliasDeclaration") {
|
|
19771
|
+
if (resolved.typeAnnotation.type === "TSFunctionType") {
|
|
19772
|
+
return ["Function"];
|
|
19773
|
+
}
|
|
19774
|
+
if (node.typeParameters) {
|
|
19775
|
+
const typeParams = /* @__PURE__ */ Object.create(null);
|
|
19776
|
+
if (resolved.typeParameters) {
|
|
19777
|
+
resolved.typeParameters.params.forEach((p, i) => {
|
|
19778
|
+
typeParams[p.name] = node.typeParameters.params[i];
|
|
19779
|
+
});
|
|
19780
|
+
}
|
|
19781
|
+
return inferRuntimeType(
|
|
19782
|
+
ctx,
|
|
19783
|
+
resolved.typeAnnotation,
|
|
19784
|
+
resolved._ownerScope,
|
|
19785
|
+
isKeyOf,
|
|
19786
|
+
typeParams
|
|
19787
|
+
);
|
|
19788
|
+
}
|
|
19725
19789
|
}
|
|
19726
19790
|
return inferRuntimeType(ctx, resolved, resolved._ownerScope, isKeyOf);
|
|
19727
19791
|
}
|
|
19728
19792
|
if (node.typeName.type === "Identifier") {
|
|
19793
|
+
if (typeParameters && typeParameters[node.typeName.name]) {
|
|
19794
|
+
return inferRuntimeType(
|
|
19795
|
+
ctx,
|
|
19796
|
+
typeParameters[node.typeName.name],
|
|
19797
|
+
scope,
|
|
19798
|
+
isKeyOf,
|
|
19799
|
+
typeParameters
|
|
19800
|
+
);
|
|
19801
|
+
}
|
|
19729
19802
|
if (isKeyOf) {
|
|
19730
19803
|
switch (node.typeName.name) {
|
|
19731
19804
|
case "String":
|
|
@@ -19848,11 +19921,33 @@ function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx)
|
|
|
19848
19921
|
case "TSParenthesizedType":
|
|
19849
19922
|
return inferRuntimeType(ctx, node.typeAnnotation, scope);
|
|
19850
19923
|
case "TSUnionType":
|
|
19851
|
-
return flattenTypes(ctx, node.types, scope, isKeyOf);
|
|
19924
|
+
return flattenTypes(ctx, node.types, scope, isKeyOf, typeParameters);
|
|
19852
19925
|
case "TSIntersectionType": {
|
|
19853
|
-
return flattenTypes(
|
|
19854
|
-
|
|
19855
|
-
|
|
19926
|
+
return flattenTypes(
|
|
19927
|
+
ctx,
|
|
19928
|
+
node.types,
|
|
19929
|
+
scope,
|
|
19930
|
+
isKeyOf,
|
|
19931
|
+
typeParameters
|
|
19932
|
+
).filter((t) => t !== UNKNOWN_TYPE);
|
|
19933
|
+
}
|
|
19934
|
+
case "TSMappedType": {
|
|
19935
|
+
const { typeAnnotation, typeParameter } = node;
|
|
19936
|
+
if (typeAnnotation && typeAnnotation.type === "TSIndexedAccessType" && typeParameter && typeParameter.constraint && typeParameters) {
|
|
19937
|
+
const constraint = typeParameter.constraint;
|
|
19938
|
+
if (constraint.type === "TSTypeOperator" && constraint.operator === "keyof" && constraint.typeAnnotation && constraint.typeAnnotation.type === "TSTypeReference" && constraint.typeAnnotation.typeName.type === "Identifier") {
|
|
19939
|
+
const typeName = constraint.typeAnnotation.typeName.name;
|
|
19940
|
+
const index = typeAnnotation.indexType;
|
|
19941
|
+
const obj = typeAnnotation.objectType;
|
|
19942
|
+
if (obj && obj.type === "TSTypeReference" && obj.typeName.type === "Identifier" && obj.typeName.name === typeName && index && index.type === "TSTypeReference" && index.typeName.type === "Identifier" && index.typeName.name === typeParameter.name) {
|
|
19943
|
+
const targetType = typeParameters[typeName];
|
|
19944
|
+
if (targetType) {
|
|
19945
|
+
return inferRuntimeType(ctx, targetType, scope);
|
|
19946
|
+
}
|
|
19947
|
+
}
|
|
19948
|
+
}
|
|
19949
|
+
}
|
|
19950
|
+
return [UNKNOWN_TYPE];
|
|
19856
19951
|
}
|
|
19857
19952
|
case "TSEnumDeclaration":
|
|
19858
19953
|
return inferEnumType(node);
|
|
@@ -19907,14 +20002,16 @@ function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx)
|
|
|
19907
20002
|
}
|
|
19908
20003
|
return [UNKNOWN_TYPE];
|
|
19909
20004
|
}
|
|
19910
|
-
function flattenTypes(ctx, types, scope, isKeyOf = false) {
|
|
20005
|
+
function flattenTypes(ctx, types, scope, isKeyOf = false, typeParameters = void 0) {
|
|
19911
20006
|
if (types.length === 1) {
|
|
19912
|
-
return inferRuntimeType(ctx, types[0], scope, isKeyOf);
|
|
20007
|
+
return inferRuntimeType(ctx, types[0], scope, isKeyOf, typeParameters);
|
|
19913
20008
|
}
|
|
19914
20009
|
return [
|
|
19915
20010
|
...new Set(
|
|
19916
20011
|
[].concat(
|
|
19917
|
-
...types.map(
|
|
20012
|
+
...types.map(
|
|
20013
|
+
(t) => inferRuntimeType(ctx, t, scope, isKeyOf, typeParameters)
|
|
20014
|
+
)
|
|
19918
20015
|
)
|
|
19919
20016
|
)
|
|
19920
20017
|
];
|
|
@@ -20000,7 +20097,7 @@ function ctorToType(ctorType) {
|
|
|
20000
20097
|
}
|
|
20001
20098
|
function findStaticPropertyType(node, key) {
|
|
20002
20099
|
const prop = node.members.find(
|
|
20003
|
-
(m) => m.type === "TSPropertySignature" &&
|
|
20100
|
+
(m) => m.type === "TSPropertySignature" && getStringLiteralKey(m) === key && m.typeAnnotation
|
|
20004
20101
|
);
|
|
20005
20102
|
return prop && prop.typeAnnotation.typeAnnotation;
|
|
20006
20103
|
}
|
|
@@ -20804,7 +20901,6 @@ function compileScript(sfc, options) {
|
|
|
20804
20901
|
Upgrade your vite or vue-loader version for compatibility with the latest experimental proposals.`
|
|
20805
20902
|
);
|
|
20806
20903
|
}
|
|
20807
|
-
const ctx = new ScriptCompileContext(sfc, options);
|
|
20808
20904
|
const { script, scriptSetup, source, filename } = sfc;
|
|
20809
20905
|
const hoistStatic = options.hoistStatic !== false && !script;
|
|
20810
20906
|
const scopeId = options.id ? options.id.replace(/^data-v-/, "") : "";
|
|
@@ -20812,20 +20908,27 @@ Upgrade your vite or vue-loader version for compatibility with the latest experi
|
|
|
20812
20908
|
const scriptSetupLang = scriptSetup && scriptSetup.lang;
|
|
20813
20909
|
const vapor = sfc.vapor || options.vapor;
|
|
20814
20910
|
const ssr = (_a = options.templateOptions) == null ? void 0 : _a.ssr;
|
|
20911
|
+
const setupPreambleLines = [];
|
|
20912
|
+
const isJSOrTS = isJS(scriptLang, scriptSetupLang) || isTS(scriptLang, scriptSetupLang);
|
|
20913
|
+
if (script && scriptSetup && scriptLang !== scriptSetupLang) {
|
|
20914
|
+
throw new Error(
|
|
20915
|
+
`[@vue/compiler-sfc] <script> and <script setup> must have the same language type.`
|
|
20916
|
+
);
|
|
20917
|
+
}
|
|
20815
20918
|
if (!scriptSetup) {
|
|
20816
20919
|
if (!script) {
|
|
20817
20920
|
throw new Error(`[@vue/compiler-sfc] SFC contains no <script> tags.`);
|
|
20818
20921
|
}
|
|
20819
|
-
|
|
20820
|
-
|
|
20821
|
-
|
|
20822
|
-
|
|
20823
|
-
|
|
20824
|
-
);
|
|
20922
|
+
if (script.lang && !isJSOrTS) {
|
|
20923
|
+
return script;
|
|
20924
|
+
}
|
|
20925
|
+
const ctx2 = new ScriptCompileContext(sfc, options);
|
|
20926
|
+
return processNormalScript(ctx2, scopeId);
|
|
20825
20927
|
}
|
|
20826
|
-
if (scriptSetupLang && !
|
|
20928
|
+
if (scriptSetupLang && !isJSOrTS) {
|
|
20827
20929
|
return scriptSetup;
|
|
20828
20930
|
}
|
|
20931
|
+
const ctx = new ScriptCompileContext(sfc, options);
|
|
20829
20932
|
const scriptBindings = /* @__PURE__ */ Object.create(null);
|
|
20830
20933
|
const setupBindings = /* @__PURE__ */ Object.create(null);
|
|
20831
20934
|
let defaultExport;
|
|
@@ -20851,9 +20954,9 @@ Upgrade your vite or vue-loader version for compatibility with the latest experi
|
|
|
20851
20954
|
ctx.s.move(start, end, 0);
|
|
20852
20955
|
}
|
|
20853
20956
|
function registerUserImport(source2, local, imported, isType, isFromSetup, needTemplateUsageCheck) {
|
|
20854
|
-
let
|
|
20957
|
+
let isImportUsed = needTemplateUsageCheck;
|
|
20855
20958
|
if (needTemplateUsageCheck && ctx.isTS && sfc.template && !sfc.template.src && !sfc.template.lang) {
|
|
20856
|
-
|
|
20959
|
+
isImportUsed = isUsedInTemplate(local, sfc);
|
|
20857
20960
|
}
|
|
20858
20961
|
ctx.userImports[local] = {
|
|
20859
20962
|
isType,
|
|
@@ -20861,7 +20964,7 @@ Upgrade your vite or vue-loader version for compatibility with the latest experi
|
|
|
20861
20964
|
local,
|
|
20862
20965
|
source: source2,
|
|
20863
20966
|
isFromSetup,
|
|
20864
|
-
isUsedInTemplate
|
|
20967
|
+
isUsedInTemplate: isImportUsed
|
|
20865
20968
|
};
|
|
20866
20969
|
}
|
|
20867
20970
|
function checkInvalidScopeReference(node, method) {
|
|
@@ -20876,8 +20979,36 @@ Upgrade your vite or vue-loader version for compatibility with the latest experi
|
|
|
20876
20979
|
}
|
|
20877
20980
|
});
|
|
20878
20981
|
}
|
|
20982
|
+
function buildDestructureElements() {
|
|
20983
|
+
if (!sfc.template || !sfc.template.ast) return;
|
|
20984
|
+
const builtins = {
|
|
20985
|
+
$props: {
|
|
20986
|
+
bindingType: "setup-reactive-const",
|
|
20987
|
+
setup: () => setupPreambleLines.push(`const $props = __props`)
|
|
20988
|
+
},
|
|
20989
|
+
$emit: {
|
|
20990
|
+
bindingType: "setup-const",
|
|
20991
|
+
setup: () => ctx.emitDecl ? setupPreambleLines.push(`const $emit = __emit`) : destructureElements.push("emit: $emit")
|
|
20992
|
+
},
|
|
20993
|
+
$attrs: {
|
|
20994
|
+
bindingType: "setup-reactive-const",
|
|
20995
|
+
setup: () => destructureElements.push("attrs: $attrs")
|
|
20996
|
+
},
|
|
20997
|
+
$slots: {
|
|
20998
|
+
bindingType: "setup-reactive-const",
|
|
20999
|
+
setup: () => destructureElements.push("slots: $slots")
|
|
21000
|
+
}
|
|
21001
|
+
};
|
|
21002
|
+
for (const [name, config] of Object.entries(builtins)) {
|
|
21003
|
+
if (isUsedInTemplate(name, sfc) && !ctx.bindingMetadata[name]) {
|
|
21004
|
+
config.setup();
|
|
21005
|
+
ctx.bindingMetadata[name] = config.bindingType;
|
|
21006
|
+
}
|
|
21007
|
+
}
|
|
21008
|
+
}
|
|
20879
21009
|
const scriptAst = ctx.scriptAst;
|
|
20880
21010
|
const scriptSetupAst = ctx.scriptSetupAst;
|
|
21011
|
+
const inlineMode = options.inlineTemplate;
|
|
20881
21012
|
if (scriptAst) {
|
|
20882
21013
|
for (const node of scriptAst.body) {
|
|
20883
21014
|
if (node.type === "ImportDeclaration") {
|
|
@@ -20889,7 +21020,7 @@ Upgrade your vite or vue-loader version for compatibility with the latest experi
|
|
|
20889
21020
|
imported,
|
|
20890
21021
|
node.importKind === "type" || specifier.type === "ImportSpecifier" && specifier.importKind === "type",
|
|
20891
21022
|
false,
|
|
20892
|
-
!
|
|
21023
|
+
!inlineMode
|
|
20893
21024
|
);
|
|
20894
21025
|
}
|
|
20895
21026
|
}
|
|
@@ -20914,6 +21045,13 @@ Upgrade your vite or vue-loader version for compatibility with the latest experi
|
|
|
20914
21045
|
const local = specifier.local.name;
|
|
20915
21046
|
const imported = getImportedName(specifier);
|
|
20916
21047
|
const source2 = node.source.value;
|
|
21048
|
+
if (vapor && ssr && specifier.type === "ImportSpecifier" && source2 === "vue" && imported === "defineVaporAsyncComponent") {
|
|
21049
|
+
ctx.s.overwrite(
|
|
21050
|
+
specifier.start + startOffset,
|
|
21051
|
+
specifier.end + startOffset,
|
|
21052
|
+
`defineAsyncComponent as ${local}`
|
|
21053
|
+
);
|
|
21054
|
+
}
|
|
20917
21055
|
const existing = ctx.userImports[local];
|
|
20918
21056
|
if (source2 === "vue" && MACROS.includes(imported)) {
|
|
20919
21057
|
if (local === imported) {
|
|
@@ -20943,7 +21081,7 @@ Upgrade your vite or vue-loader version for compatibility with the latest experi
|
|
|
20943
21081
|
imported,
|
|
20944
21082
|
node.importKind === "type" || specifier.type === "ImportSpecifier" && specifier.importKind === "type",
|
|
20945
21083
|
true,
|
|
20946
|
-
!
|
|
21084
|
+
!inlineMode
|
|
20947
21085
|
);
|
|
20948
21086
|
}
|
|
20949
21087
|
}
|
|
@@ -21247,16 +21385,20 @@ ${genCssVarsCode(
|
|
|
21247
21385
|
let __temp${any}, __restore${any}
|
|
21248
21386
|
`);
|
|
21249
21387
|
}
|
|
21250
|
-
const destructureElements = ctx.hasDefineExposeCall || !
|
|
21388
|
+
const destructureElements = ctx.hasDefineExposeCall || !inlineMode ? [`expose: __expose`] : [];
|
|
21251
21389
|
if (ctx.emitDecl) {
|
|
21252
21390
|
destructureElements.push(`emit: __emit`);
|
|
21253
21391
|
}
|
|
21392
|
+
if (inlineMode) {
|
|
21393
|
+
buildDestructureElements();
|
|
21394
|
+
}
|
|
21254
21395
|
if (destructureElements.length) {
|
|
21255
21396
|
args += `, { ${destructureElements.join(", ")} }`;
|
|
21256
21397
|
}
|
|
21257
21398
|
let templateMap;
|
|
21258
21399
|
let returned;
|
|
21259
|
-
|
|
21400
|
+
const propsDecl = genRuntimeProps(ctx);
|
|
21401
|
+
if (!inlineMode || !sfc.template && ctx.hasDefaultExportRender) {
|
|
21260
21402
|
const allBindings = {
|
|
21261
21403
|
...scriptBindings,
|
|
21262
21404
|
...setupBindings
|
|
@@ -21332,7 +21474,7 @@ let __temp${any}, __restore${any}
|
|
|
21332
21474
|
returned = `() => {}`;
|
|
21333
21475
|
}
|
|
21334
21476
|
}
|
|
21335
|
-
if (!
|
|
21477
|
+
if (!inlineMode && true) {
|
|
21336
21478
|
ctx.s.appendRight(
|
|
21337
21479
|
endOffset,
|
|
21338
21480
|
`
|
|
@@ -21367,7 +21509,6 @@ ${vapor && !ssr ? `` : `return `}${returned}
|
|
|
21367
21509
|
runtimeOptions += `
|
|
21368
21510
|
__ssrInlineRender: true,`;
|
|
21369
21511
|
}
|
|
21370
|
-
const propsDecl = genRuntimeProps(ctx);
|
|
21371
21512
|
if (propsDecl) runtimeOptions += `
|
|
21372
21513
|
props: ${propsDecl},`;
|
|
21373
21514
|
const emitsDecl = genRuntimeEmits(ctx);
|
|
@@ -21377,9 +21518,15 @@ ${vapor && !ssr ? `` : `return `}${returned}
|
|
|
21377
21518
|
if (ctx.optionsRuntimeDecl) {
|
|
21378
21519
|
definedOptions = scriptSetup.content.slice(ctx.optionsRuntimeDecl.start, ctx.optionsRuntimeDecl.end).trim();
|
|
21379
21520
|
}
|
|
21380
|
-
|
|
21381
|
-
|
|
21521
|
+
if (!ctx.hasDefineExposeCall && !inlineMode)
|
|
21522
|
+
setupPreambleLines.push(`__expose();`);
|
|
21523
|
+
const setupPreamble = setupPreambleLines.length ? ` ${setupPreambleLines.join("\n ")}
|
|
21524
|
+
` : "";
|
|
21382
21525
|
if (ctx.isTS) {
|
|
21526
|
+
if (ssr && vapor) {
|
|
21527
|
+
runtimeOptions += `
|
|
21528
|
+
__vapor: true,`;
|
|
21529
|
+
}
|
|
21383
21530
|
const def = (defaultExport ? `
|
|
21384
21531
|
...${normalScriptDefaultVar},` : ``) + (definedOptions ? `
|
|
21385
21532
|
...${definedOptions},` : "");
|
|
@@ -21390,7 +21537,7 @@ ${genDefaultAs} /*@__PURE__*/${ctx.helper(
|
|
|
21390
21537
|
vapor && !ssr ? `defineVaporComponent` : `defineComponent`
|
|
21391
21538
|
)}({${def}${runtimeOptions}
|
|
21392
21539
|
${hasAwait ? `async ` : ``}setup(${args}) {
|
|
21393
|
-
${
|
|
21540
|
+
${setupPreamble}`
|
|
21394
21541
|
);
|
|
21395
21542
|
ctx.s.appendRight(endOffset, `})`);
|
|
21396
21543
|
} else {
|
|
@@ -21404,7 +21551,7 @@ ${exposeCall}`
|
|
|
21404
21551
|
`
|
|
21405
21552
|
${genDefaultAs} /*@__PURE__*/Object.assign(${defaultExport ? `${normalScriptDefaultVar}, ` : ""}${definedOptions ? `${definedOptions}, ` : ""}{${runtimeOptions}
|
|
21406
21553
|
${hasAwait ? `async ` : ``}setup(${args}) {
|
|
21407
|
-
${
|
|
21554
|
+
${setupPreamble}`
|
|
21408
21555
|
);
|
|
21409
21556
|
ctx.s.appendRight(endOffset, `})`);
|
|
21410
21557
|
} else {
|
|
@@ -21413,7 +21560,7 @@ ${exposeCall}`
|
|
|
21413
21560
|
`
|
|
21414
21561
|
${genDefaultAs} {${runtimeOptions}
|
|
21415
21562
|
${hasAwait ? `async ` : ``}setup(${args}) {
|
|
21416
|
-
${
|
|
21563
|
+
${setupPreamble}`
|
|
21417
21564
|
);
|
|
21418
21565
|
ctx.s.appendRight(endOffset, `}`);
|
|
21419
21566
|
}
|
|
@@ -21612,7 +21759,7 @@ function mergeSourceMaps(scriptMap, templateMap, templateLineOffset) {
|
|
|
21612
21759
|
return generator.toJSON();
|
|
21613
21760
|
}
|
|
21614
21761
|
|
|
21615
|
-
const version = "3.6.0-alpha.
|
|
21762
|
+
const version = "3.6.0-alpha.3";
|
|
21616
21763
|
const parseCache = parseCache$1;
|
|
21617
21764
|
const errorMessages = {
|
|
21618
21765
|
...CompilerDOM.errorMessages,
|