@vue/compiler-sfc 2.7.0-beta.2 → 2.7.0-beta.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.d.ts +22 -11
- package/dist/compiler-sfc.js +301 -168
- package/package.json +1 -1
package/dist/compiler-sfc.d.ts
CHANGED
|
@@ -261,16 +261,7 @@ declare type ModuleOptions = {
|
|
|
261
261
|
staticKeys?: Array<string>;
|
|
262
262
|
};
|
|
263
263
|
|
|
264
|
-
export declare function parse(options:
|
|
265
|
-
|
|
266
|
-
declare interface ParseOptions {
|
|
267
|
-
source: string;
|
|
268
|
-
filename?: string;
|
|
269
|
-
compiler?: TemplateCompiler;
|
|
270
|
-
compilerParseOptions?: VueTemplateCompilerParseOptions;
|
|
271
|
-
sourceRoot?: string;
|
|
272
|
-
sourceMap?: boolean;
|
|
273
|
-
}
|
|
264
|
+
export declare function parse(options: SFCParseOptions): SFCDescriptor;
|
|
274
265
|
|
|
275
266
|
declare interface RawSourceMap extends StartOfSourceMap {
|
|
276
267
|
version: string;
|
|
@@ -312,7 +303,8 @@ export declare interface SFCDescriptor {
|
|
|
312
303
|
scriptSetup: SFCScriptBlock | null;
|
|
313
304
|
styles: SFCBlock[];
|
|
314
305
|
customBlocks: SFCCustomBlock[];
|
|
315
|
-
|
|
306
|
+
cssVars: string[];
|
|
307
|
+
errors: (string | WarningMessage)[];
|
|
316
308
|
/**
|
|
317
309
|
* compare with an existing descriptor to determine whether HMR should perform
|
|
318
310
|
* a reload vs. re-render.
|
|
@@ -324,6 +316,19 @@ export declare interface SFCDescriptor {
|
|
|
324
316
|
shouldForceReload: (prevImports: Record<string, ImportBinding>) => boolean;
|
|
325
317
|
}
|
|
326
318
|
|
|
319
|
+
export declare interface SFCParseOptions {
|
|
320
|
+
source: string;
|
|
321
|
+
filename?: string;
|
|
322
|
+
compiler?: TemplateCompiler;
|
|
323
|
+
compilerParseOptions?: VueTemplateCompilerParseOptions;
|
|
324
|
+
sourceRoot?: string;
|
|
325
|
+
sourceMap?: boolean;
|
|
326
|
+
/**
|
|
327
|
+
* @deprecated use `sourceMap` instead.
|
|
328
|
+
*/
|
|
329
|
+
needMap?: boolean;
|
|
330
|
+
}
|
|
331
|
+
|
|
327
332
|
export declare interface SFCScriptBlock extends SFCBlock {
|
|
328
333
|
type: 'script';
|
|
329
334
|
setup?: string | boolean;
|
|
@@ -340,6 +345,11 @@ export declare interface SFCScriptBlock extends SFCBlock {
|
|
|
340
345
|
}
|
|
341
346
|
|
|
342
347
|
export declare interface SFCScriptCompileOptions {
|
|
348
|
+
/**
|
|
349
|
+
* Scope ID for prefixing injected CSS variables.
|
|
350
|
+
* This must be consistent with the `id` passed to `compileStyle`.
|
|
351
|
+
*/
|
|
352
|
+
id: string;
|
|
343
353
|
/**
|
|
344
354
|
* Production mode. Used to determine whether to generate hashed CSS variables
|
|
345
355
|
*/
|
|
@@ -365,6 +375,7 @@ export declare interface SFCStyleCompileOptions {
|
|
|
365
375
|
preprocessOptions?: any;
|
|
366
376
|
postcssOptions?: any;
|
|
367
377
|
postcssPlugins?: any[];
|
|
378
|
+
isProd?: boolean;
|
|
368
379
|
}
|
|
369
380
|
|
|
370
381
|
export declare interface SFCStyleCompileResults {
|
package/dist/compiler-sfc.js
CHANGED
|
@@ -658,6 +658,7 @@ function parseComponent(source, options = {}) {
|
|
|
658
658
|
scriptSetup: null,
|
|
659
659
|
styles: [],
|
|
660
660
|
customBlocks: [],
|
|
661
|
+
cssVars: [],
|
|
661
662
|
errors: [],
|
|
662
663
|
shouldForceReload: null // attached in parse() by compiler-sfc
|
|
663
664
|
};
|
|
@@ -7959,6 +7960,268 @@ function warn(msg) {
|
|
|
7959
7960
|
console.warn(`\x1b[1m\x1b[33m[@vue/compiler-sfc]\x1b[0m\x1b[33m ${msg}\x1b[0m\n`);
|
|
7960
7961
|
}
|
|
7961
7962
|
|
|
7963
|
+
const doNotPrefix = makeMap('Infinity,undefined,NaN,isFinite,isNaN,' +
|
|
7964
|
+
'parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' +
|
|
7965
|
+
'Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,' +
|
|
7966
|
+
'require,' + // for webpack
|
|
7967
|
+
'arguments,' + // parsed as identifier but is a special keyword...
|
|
7968
|
+
'_c' // cached to save property access
|
|
7969
|
+
);
|
|
7970
|
+
/**
|
|
7971
|
+
* The input is expected to be a valid expression.
|
|
7972
|
+
*/
|
|
7973
|
+
function prefixIdentifiers(source, isFunctional = false, isTS = false, babelOptions = {}, bindings) {
|
|
7974
|
+
const s = new MagicString(source);
|
|
7975
|
+
const plugins = [
|
|
7976
|
+
...(isTS ? ['typescript'] : []),
|
|
7977
|
+
...((babelOptions === null || babelOptions === void 0 ? void 0 : babelOptions.plugins) || [])
|
|
7978
|
+
];
|
|
7979
|
+
const ast = parser$1.parseExpression(source, Object.assign(Object.assign({}, babelOptions), { plugins }));
|
|
7980
|
+
const isScriptSetup = bindings && bindings.__isScriptSetup !== false;
|
|
7981
|
+
walkIdentifiers(ast, ident => {
|
|
7982
|
+
const { name } = ident;
|
|
7983
|
+
if (doNotPrefix(name)) {
|
|
7984
|
+
return;
|
|
7985
|
+
}
|
|
7986
|
+
if (!isScriptSetup) {
|
|
7987
|
+
s.prependRight(ident.start, '_vm.');
|
|
7988
|
+
return;
|
|
7989
|
+
}
|
|
7990
|
+
s.overwrite(ident.start, ident.end, rewriteIdentifier(name, bindings));
|
|
7991
|
+
}, node => {
|
|
7992
|
+
if (node.type === 'WithStatement') {
|
|
7993
|
+
s.remove(node.start, node.body.start + 1);
|
|
7994
|
+
s.remove(node.end - 1, node.end);
|
|
7995
|
+
if (!isFunctional) {
|
|
7996
|
+
s.prependRight(node.start, `var _vm=this,_c=_vm._self._c${isScriptSetup ? `,_setup=_vm._self._setupProxy;` : `;`}`);
|
|
7997
|
+
}
|
|
7998
|
+
}
|
|
7999
|
+
});
|
|
8000
|
+
return s.toString();
|
|
8001
|
+
}
|
|
8002
|
+
function rewriteIdentifier(name, bindings) {
|
|
8003
|
+
const type = bindings[name];
|
|
8004
|
+
if (type && type.startsWith('setup')) {
|
|
8005
|
+
return `_setup.${name}`;
|
|
8006
|
+
}
|
|
8007
|
+
else {
|
|
8008
|
+
return `_vm.${name}`;
|
|
8009
|
+
}
|
|
8010
|
+
}
|
|
8011
|
+
|
|
8012
|
+
const CSS_VARS_HELPER = `useCssVars`;
|
|
8013
|
+
function genCssVarsFromList(vars, id, isProd, isSSR = false) {
|
|
8014
|
+
return `{\n ${vars
|
|
8015
|
+
.map(key => `"${isSSR ? `--` : ``}${genVarName(id, key, isProd)}": (${key})`)
|
|
8016
|
+
.join(',\n ')}\n}`;
|
|
8017
|
+
}
|
|
8018
|
+
function genVarName(id, raw, isProd) {
|
|
8019
|
+
if (isProd) {
|
|
8020
|
+
return hashSum(id + raw);
|
|
8021
|
+
}
|
|
8022
|
+
else {
|
|
8023
|
+
return `${id}-${raw.replace(/([^\w-])/g, '_')}`;
|
|
8024
|
+
}
|
|
8025
|
+
}
|
|
8026
|
+
function normalizeExpression(exp) {
|
|
8027
|
+
exp = exp.trim();
|
|
8028
|
+
if ((exp[0] === `'` && exp[exp.length - 1] === `'`) ||
|
|
8029
|
+
(exp[0] === `"` && exp[exp.length - 1] === `"`)) {
|
|
8030
|
+
return exp.slice(1, -1);
|
|
8031
|
+
}
|
|
8032
|
+
return exp;
|
|
8033
|
+
}
|
|
8034
|
+
const vBindRE = /v-bind\s*\(/g;
|
|
8035
|
+
function parseCssVars(sfc) {
|
|
8036
|
+
const vars = [];
|
|
8037
|
+
sfc.styles.forEach(style => {
|
|
8038
|
+
let match;
|
|
8039
|
+
// ignore v-bind() in comments /* ... */
|
|
8040
|
+
const content = style.content.replace(/\/\*([\s\S]*?)\*\//g, '');
|
|
8041
|
+
while ((match = vBindRE.exec(content))) {
|
|
8042
|
+
const start = match.index + match[0].length;
|
|
8043
|
+
const end = lexBinding(content, start);
|
|
8044
|
+
if (end !== null) {
|
|
8045
|
+
const variable = normalizeExpression(content.slice(start, end));
|
|
8046
|
+
if (!vars.includes(variable)) {
|
|
8047
|
+
vars.push(variable);
|
|
8048
|
+
}
|
|
8049
|
+
}
|
|
8050
|
+
}
|
|
8051
|
+
});
|
|
8052
|
+
return vars;
|
|
8053
|
+
}
|
|
8054
|
+
function lexBinding(content, start) {
|
|
8055
|
+
let state = 0 /* LexerState.inParens */;
|
|
8056
|
+
let parenDepth = 0;
|
|
8057
|
+
for (let i = start; i < content.length; i++) {
|
|
8058
|
+
const char = content.charAt(i);
|
|
8059
|
+
switch (state) {
|
|
8060
|
+
case 0 /* LexerState.inParens */:
|
|
8061
|
+
if (char === `'`) {
|
|
8062
|
+
state = 1 /* LexerState.inSingleQuoteString */;
|
|
8063
|
+
}
|
|
8064
|
+
else if (char === `"`) {
|
|
8065
|
+
state = 2 /* LexerState.inDoubleQuoteString */;
|
|
8066
|
+
}
|
|
8067
|
+
else if (char === `(`) {
|
|
8068
|
+
parenDepth++;
|
|
8069
|
+
}
|
|
8070
|
+
else if (char === `)`) {
|
|
8071
|
+
if (parenDepth > 0) {
|
|
8072
|
+
parenDepth--;
|
|
8073
|
+
}
|
|
8074
|
+
else {
|
|
8075
|
+
return i;
|
|
8076
|
+
}
|
|
8077
|
+
}
|
|
8078
|
+
break;
|
|
8079
|
+
case 1 /* LexerState.inSingleQuoteString */:
|
|
8080
|
+
if (char === `'`) {
|
|
8081
|
+
state = 0 /* LexerState.inParens */;
|
|
8082
|
+
}
|
|
8083
|
+
break;
|
|
8084
|
+
case 2 /* LexerState.inDoubleQuoteString */:
|
|
8085
|
+
if (char === `"`) {
|
|
8086
|
+
state = 0 /* LexerState.inParens */;
|
|
8087
|
+
}
|
|
8088
|
+
break;
|
|
8089
|
+
}
|
|
8090
|
+
}
|
|
8091
|
+
return null;
|
|
8092
|
+
}
|
|
8093
|
+
const cssVarsPlugin = opts => {
|
|
8094
|
+
const { id, isProd } = opts;
|
|
8095
|
+
return {
|
|
8096
|
+
postcssPlugin: 'vue-sfc-vars',
|
|
8097
|
+
Declaration(decl) {
|
|
8098
|
+
// rewrite CSS variables
|
|
8099
|
+
const value = decl.value;
|
|
8100
|
+
if (vBindRE.test(value)) {
|
|
8101
|
+
vBindRE.lastIndex = 0;
|
|
8102
|
+
let transformed = '';
|
|
8103
|
+
let lastIndex = 0;
|
|
8104
|
+
let match;
|
|
8105
|
+
while ((match = vBindRE.exec(value))) {
|
|
8106
|
+
const start = match.index + match[0].length;
|
|
8107
|
+
const end = lexBinding(value, start);
|
|
8108
|
+
if (end !== null) {
|
|
8109
|
+
const variable = normalizeExpression(value.slice(start, end));
|
|
8110
|
+
transformed +=
|
|
8111
|
+
value.slice(lastIndex, match.index) +
|
|
8112
|
+
`var(--${genVarName(id, variable, isProd)})`;
|
|
8113
|
+
lastIndex = end + 1;
|
|
8114
|
+
}
|
|
8115
|
+
}
|
|
8116
|
+
decl.value = transformed + value.slice(lastIndex);
|
|
8117
|
+
}
|
|
8118
|
+
}
|
|
8119
|
+
};
|
|
8120
|
+
};
|
|
8121
|
+
cssVarsPlugin.postcss = true;
|
|
8122
|
+
function genCssVarsCode(vars, bindings, id, isProd) {
|
|
8123
|
+
const varsExp = genCssVarsFromList(vars, id, isProd);
|
|
8124
|
+
return `_${CSS_VARS_HELPER}((_vm, _setup) => ${prefixIdentifiers(`(${varsExp})`, false, false, undefined, bindings)})`;
|
|
8125
|
+
}
|
|
8126
|
+
// <script setup> already gets the calls injected as part of the transform
|
|
8127
|
+
// this is only for single normal <script>
|
|
8128
|
+
function genNormalScriptCssVarsCode(cssVars, bindings, id, isProd) {
|
|
8129
|
+
return (`\nimport { ${CSS_VARS_HELPER} as _${CSS_VARS_HELPER} } from 'vue'\n` +
|
|
8130
|
+
`const __injectCSSVars__ = () => {\n${genCssVarsCode(cssVars, bindings, id, isProd)}}\n` +
|
|
8131
|
+
`const __setup__ = __default__.setup\n` +
|
|
8132
|
+
`__default__.setup = __setup__\n` +
|
|
8133
|
+
` ? (props, ctx) => { __injectCSSVars__();return __setup__(props, ctx) }\n` +
|
|
8134
|
+
` : __injectCSSVars__\n`);
|
|
8135
|
+
}
|
|
8136
|
+
|
|
8137
|
+
const defaultExportRE = /((?:^|\n|;)\s*)export(\s*)default/;
|
|
8138
|
+
const namedDefaultExportRE = /((?:^|\n|;)\s*)export(.+)(?:as)?(\s*)default/s;
|
|
8139
|
+
const exportDefaultClassRE = /((?:^|\n|;)\s*)export\s+default\s+class\s+([\w$]+)/;
|
|
8140
|
+
/**
|
|
8141
|
+
* Utility for rewriting `export default` in a script block into a variable
|
|
8142
|
+
* declaration so that we can inject things into it
|
|
8143
|
+
*/
|
|
8144
|
+
function rewriteDefault(input, as, parserPlugins) {
|
|
8145
|
+
if (!hasDefaultExport(input)) {
|
|
8146
|
+
return input + `\nconst ${as} = {}`;
|
|
8147
|
+
}
|
|
8148
|
+
let replaced;
|
|
8149
|
+
const classMatch = input.match(exportDefaultClassRE);
|
|
8150
|
+
if (classMatch) {
|
|
8151
|
+
replaced =
|
|
8152
|
+
input.replace(exportDefaultClassRE, '$1class $2') +
|
|
8153
|
+
`\nconst ${as} = ${classMatch[2]}`;
|
|
8154
|
+
}
|
|
8155
|
+
else {
|
|
8156
|
+
replaced = input.replace(defaultExportRE, `$1const ${as} =`);
|
|
8157
|
+
}
|
|
8158
|
+
if (!hasDefaultExport(replaced)) {
|
|
8159
|
+
return replaced;
|
|
8160
|
+
}
|
|
8161
|
+
// if the script somehow still contains `default export`, it probably has
|
|
8162
|
+
// multi-line comments or template strings. fallback to a full parse.
|
|
8163
|
+
const s = new MagicString(input);
|
|
8164
|
+
const ast = parser$1.parse(input, {
|
|
8165
|
+
sourceType: 'module',
|
|
8166
|
+
plugins: parserPlugins
|
|
8167
|
+
}).program.body;
|
|
8168
|
+
ast.forEach(node => {
|
|
8169
|
+
if (node.type === 'ExportDefaultDeclaration') {
|
|
8170
|
+
s.overwrite(node.start, node.declaration.start, `const ${as} = `);
|
|
8171
|
+
}
|
|
8172
|
+
if (node.type === 'ExportNamedDeclaration') {
|
|
8173
|
+
for (const specifier of node.specifiers) {
|
|
8174
|
+
if (specifier.type === 'ExportSpecifier' &&
|
|
8175
|
+
specifier.exported.type === 'Identifier' &&
|
|
8176
|
+
specifier.exported.name === 'default') {
|
|
8177
|
+
if (node.source) {
|
|
8178
|
+
if (specifier.local.name === 'default') {
|
|
8179
|
+
const end = specifierEnd(input, specifier.local.end, node.end);
|
|
8180
|
+
s.prepend(`import { default as __VUE_DEFAULT__ } from '${node.source.value}'\n`);
|
|
8181
|
+
s.overwrite(specifier.start, end, ``);
|
|
8182
|
+
s.append(`\nconst ${as} = __VUE_DEFAULT__`);
|
|
8183
|
+
continue;
|
|
8184
|
+
}
|
|
8185
|
+
else {
|
|
8186
|
+
const end = specifierEnd(input, specifier.exported.end, node.end);
|
|
8187
|
+
s.prepend(`import { ${input.slice(specifier.local.start, specifier.local.end)} } from '${node.source.value}'\n`);
|
|
8188
|
+
s.overwrite(specifier.start, end, ``);
|
|
8189
|
+
s.append(`\nconst ${as} = ${specifier.local.name}`);
|
|
8190
|
+
continue;
|
|
8191
|
+
}
|
|
8192
|
+
}
|
|
8193
|
+
const end = specifierEnd(input, specifier.end, node.end);
|
|
8194
|
+
s.overwrite(specifier.start, end, ``);
|
|
8195
|
+
s.append(`\nconst ${as} = ${specifier.local.name}`);
|
|
8196
|
+
}
|
|
8197
|
+
}
|
|
8198
|
+
}
|
|
8199
|
+
});
|
|
8200
|
+
return s.toString();
|
|
8201
|
+
}
|
|
8202
|
+
function hasDefaultExport(input) {
|
|
8203
|
+
return defaultExportRE.test(input) || namedDefaultExportRE.test(input);
|
|
8204
|
+
}
|
|
8205
|
+
function specifierEnd(input, end, nodeEnd) {
|
|
8206
|
+
// export { default , foo } ...
|
|
8207
|
+
let hasCommas = false;
|
|
8208
|
+
let oldEnd = end;
|
|
8209
|
+
while (end < nodeEnd) {
|
|
8210
|
+
if (/\s/.test(input.charAt(end))) {
|
|
8211
|
+
end++;
|
|
8212
|
+
}
|
|
8213
|
+
else if (input.charAt(end) === ',') {
|
|
8214
|
+
end++;
|
|
8215
|
+
hasCommas = true;
|
|
8216
|
+
break;
|
|
8217
|
+
}
|
|
8218
|
+
else if (input.charAt(end) === '}') {
|
|
8219
|
+
break;
|
|
8220
|
+
}
|
|
8221
|
+
}
|
|
8222
|
+
return hasCommas ? end : oldEnd;
|
|
8223
|
+
}
|
|
8224
|
+
|
|
7962
8225
|
// Special compiler macros
|
|
7963
8226
|
const DEFINE_PROPS = 'defineProps';
|
|
7964
8227
|
const DEFINE_EMITS = 'defineEmits';
|
|
@@ -7972,11 +8235,12 @@ const isBuiltInDir$1 = makeMap(`once,memo,if,for,else,else-if,slot,text,html,on,
|
|
|
7972
8235
|
* It requires the whole SFC descriptor because we need to handle and merge
|
|
7973
8236
|
* normal `<script>` + `<script setup>` if both are present.
|
|
7974
8237
|
*/
|
|
7975
|
-
function compileScript(sfc, options = {}) {
|
|
8238
|
+
function compileScript(sfc, options = { id: '' }) {
|
|
7976
8239
|
let { filename, script, scriptSetup, source } = sfc;
|
|
7977
8240
|
const isProd = !!options.isProd;
|
|
7978
8241
|
const genSourceMap = options.sourceMap !== false;
|
|
7979
|
-
|
|
8242
|
+
const cssVars = sfc.cssVars;
|
|
8243
|
+
const scopeId = options.id ? options.id.replace(/^data-v-/, '') : '';
|
|
7980
8244
|
const scriptLang = script && script.lang;
|
|
7981
8245
|
const scriptSetupLang = scriptSetup && scriptSetup.lang;
|
|
7982
8246
|
const isTS = scriptLang === 'ts' ||
|
|
@@ -8013,6 +8277,11 @@ function compileScript(sfc, options = {}) {
|
|
|
8013
8277
|
sourceType: 'module'
|
|
8014
8278
|
}).program;
|
|
8015
8279
|
const bindings = analyzeScriptBindings(scriptAst.body);
|
|
8280
|
+
if (cssVars.length) {
|
|
8281
|
+
content = rewriteDefault(content, DEFAULT_VAR, plugins);
|
|
8282
|
+
content += genNormalScriptCssVarsCode(cssVars, bindings, scopeId, isProd);
|
|
8283
|
+
content += `\nexport default ${DEFAULT_VAR}`;
|
|
8284
|
+
}
|
|
8016
8285
|
return Object.assign(Object.assign({}, script), { content,
|
|
8017
8286
|
map,
|
|
8018
8287
|
bindings, scriptAst: scriptAst.body });
|
|
@@ -8713,7 +8982,10 @@ function compileScript(sfc, options = {}) {
|
|
|
8713
8982
|
bindingMetadata[key] = setupBindings[key];
|
|
8714
8983
|
}
|
|
8715
8984
|
// 8. inject `useCssVars` calls
|
|
8716
|
-
|
|
8985
|
+
if (cssVars.length) {
|
|
8986
|
+
helperImports.add(CSS_VARS_HELPER);
|
|
8987
|
+
s.prependRight(startOffset, `\n${genCssVarsCode(cssVars, bindingMetadata, scopeId, isProd)}\n`);
|
|
8988
|
+
}
|
|
8717
8989
|
// 9. finalize setup() argument signature
|
|
8718
8990
|
let args = `__props`;
|
|
8719
8991
|
if (propsTypeDecl) {
|
|
@@ -9332,7 +9604,7 @@ const cache = new lruCache(100);
|
|
|
9332
9604
|
const splitRE = /\r?\n/g;
|
|
9333
9605
|
const emptyRE = /^(?:\/\/)?\s*$/;
|
|
9334
9606
|
function parse(options) {
|
|
9335
|
-
const { source, filename = DEFAULT_FILENAME, compiler, compilerParseOptions = { pad: false }, sourceRoot = '',
|
|
9607
|
+
const { source, filename = DEFAULT_FILENAME, compiler, compilerParseOptions = { pad: false }, sourceRoot = '', needMap = true, sourceMap = needMap } = options;
|
|
9336
9608
|
const cacheKey = hashSum(filename + source + JSON.stringify(compilerParseOptions));
|
|
9337
9609
|
let output = cache.get(cacheKey);
|
|
9338
9610
|
if (output) {
|
|
@@ -9347,6 +9619,8 @@ function parse(options) {
|
|
|
9347
9619
|
output = parseComponent(source, compilerParseOptions);
|
|
9348
9620
|
}
|
|
9349
9621
|
output.filename = filename;
|
|
9622
|
+
// parse CSS vars
|
|
9623
|
+
output.cssVars = parseCssVars(output);
|
|
9350
9624
|
output.shouldForceReload = prevImports => hmrShouldReload(prevImports, output);
|
|
9351
9625
|
if (sourceMap) {
|
|
9352
9626
|
if (output.script && !output.script.src) {
|
|
@@ -12881,57 +13155,6 @@ var _compiler = /*#__PURE__*/Object.freeze({
|
|
|
12881
13155
|
generateCodeFrame: generateCodeFrame
|
|
12882
13156
|
});
|
|
12883
13157
|
|
|
12884
|
-
const doNotPrefix = makeMap('Infinity,undefined,NaN,isFinite,isNaN,' +
|
|
12885
|
-
'parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' +
|
|
12886
|
-
'Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,' +
|
|
12887
|
-
'require,' + // for webpack
|
|
12888
|
-
'arguments,' + // parsed as identifier but is a special keyword...
|
|
12889
|
-
'_c' // cached to save property access
|
|
12890
|
-
);
|
|
12891
|
-
/**
|
|
12892
|
-
* The input is expected to be the render function code directly returned from
|
|
12893
|
-
* `compile()` calls, e.g. `with(this){return ...}`
|
|
12894
|
-
*/
|
|
12895
|
-
function prefixIdentifiers(source, fnName = '', isFunctional = false, isTS = false, babelOptions = {}, bindings) {
|
|
12896
|
-
source = `function ${fnName}(${isFunctional ? `_c,_vm` : ``}){${source}\n}`;
|
|
12897
|
-
const s = new MagicString(source);
|
|
12898
|
-
const plugins = [
|
|
12899
|
-
...(isTS ? ['typescript'] : []),
|
|
12900
|
-
...((babelOptions === null || babelOptions === void 0 ? void 0 : babelOptions.plugins) || [])
|
|
12901
|
-
];
|
|
12902
|
-
const ast = parser$1.parseExpression(source, Object.assign(Object.assign({}, babelOptions), { plugins }));
|
|
12903
|
-
const isScriptSetup = bindings && bindings.__isScriptSetup !== false;
|
|
12904
|
-
walkIdentifiers(ast, ident => {
|
|
12905
|
-
const { name } = ident;
|
|
12906
|
-
if (doNotPrefix(name)) {
|
|
12907
|
-
return;
|
|
12908
|
-
}
|
|
12909
|
-
if (!isScriptSetup) {
|
|
12910
|
-
s.prependRight(ident.start, '_vm.');
|
|
12911
|
-
return;
|
|
12912
|
-
}
|
|
12913
|
-
s.overwrite(ident.start, ident.end, rewriteIdentifier(name, bindings));
|
|
12914
|
-
}, node => {
|
|
12915
|
-
if (node.type === 'WithStatement') {
|
|
12916
|
-
s.remove(node.start, node.body.start + 1);
|
|
12917
|
-
s.remove(node.end - 1, node.end);
|
|
12918
|
-
if (!isFunctional) {
|
|
12919
|
-
s.prependRight(node.start, `var _vm=this,_c=_vm._self._c${isScriptSetup ? `,_setup=_vm._self._setupProxy;` : `;`}`);
|
|
12920
|
-
}
|
|
12921
|
-
}
|
|
12922
|
-
});
|
|
12923
|
-
return s.toString();
|
|
12924
|
-
}
|
|
12925
|
-
function rewriteIdentifier(name, bindings) {
|
|
12926
|
-
const type = bindings[name];
|
|
12927
|
-
if (type && type.startsWith('setup')) {
|
|
12928
|
-
return `_setup.${name}`;
|
|
12929
|
-
}
|
|
12930
|
-
else {
|
|
12931
|
-
return `_vm.${name}`;
|
|
12932
|
-
}
|
|
12933
|
-
}
|
|
12934
|
-
|
|
12935
13158
|
function compileTemplate(options) {
|
|
12936
13159
|
const { preprocessLang } = options;
|
|
12937
13160
|
const preprocessor = preprocessLang && consolidate[preprocessLang];
|
|
@@ -13006,8 +13229,8 @@ function actuallyCompile(options) {
|
|
|
13006
13229
|
else {
|
|
13007
13230
|
// transpile code with vue-template-es2015-compiler, which is a forked
|
|
13008
13231
|
// version of Buble that applies ES2015 transforms + stripping `with` usage
|
|
13009
|
-
let code = `var __render__ = ${prefixIdentifiers(render,
|
|
13010
|
-
`var __staticRenderFns__ = [${staticRenderFns.map(code => prefixIdentifiers(
|
|
13232
|
+
let code = `var __render__ = ${prefixIdentifiers(`function render(${isFunctional ? `_c,_vm` : ``}){${render}\n}`, isFunctional, isTS, transpileOptions, bindings)}\n` +
|
|
13233
|
+
`var __staticRenderFns__ = [${staticRenderFns.map(code => prefixIdentifiers(`function (${isFunctional ? `_c,_vm` : ``}){${code}\n}`, isFunctional, isTS, transpileOptions, bindings))}]` +
|
|
13011
13234
|
`\n`;
|
|
13012
13235
|
// #23 we use __render__ to avoid `render` not being prefixed by the
|
|
13013
13236
|
// transpiler when stripping with, but revert it back to `render` to
|
|
@@ -17279,9 +17502,8 @@ function processRule(id, rule) {
|
|
|
17279
17502
|
});
|
|
17280
17503
|
}).processSync(rule.selector);
|
|
17281
17504
|
}
|
|
17282
|
-
function rewriteSelector(id, selector, selectorRoot
|
|
17505
|
+
function rewriteSelector(id, selector, selectorRoot) {
|
|
17283
17506
|
let node = null;
|
|
17284
|
-
let shouldInject = true;
|
|
17285
17507
|
// find the last child node to insert attribute selector
|
|
17286
17508
|
selector.each(n => {
|
|
17287
17509
|
// DEPRECATED ">>>" and "/deep/" combinator
|
|
@@ -17328,23 +17550,22 @@ function rewriteSelector(id, selector, selectorRoot, slotted = false) {
|
|
|
17328
17550
|
}
|
|
17329
17551
|
return false;
|
|
17330
17552
|
}
|
|
17331
|
-
//
|
|
17332
|
-
// instead.
|
|
17553
|
+
// !!! Vue 2 does not have :slotted support
|
|
17333
17554
|
// ::v-slotted(.foo) -> .foo[xxxxxxx-s]
|
|
17334
|
-
if (value === ':slotted' || value === '::v-slotted') {
|
|
17335
|
-
|
|
17336
|
-
|
|
17337
|
-
|
|
17338
|
-
|
|
17339
|
-
|
|
17340
|
-
|
|
17341
|
-
|
|
17342
|
-
|
|
17343
|
-
|
|
17344
|
-
|
|
17345
|
-
|
|
17346
|
-
|
|
17347
|
-
}
|
|
17555
|
+
// if (value === ':slotted' || value === '::v-slotted') {
|
|
17556
|
+
// rewriteSelector(id, n.nodes[0], selectorRoot, true /* slotted */)
|
|
17557
|
+
// let last: selectorParser.Selector['nodes'][0] = n
|
|
17558
|
+
// n.nodes[0].each(ss => {
|
|
17559
|
+
// selector.insertAfter(last, ss)
|
|
17560
|
+
// last = ss
|
|
17561
|
+
// })
|
|
17562
|
+
// // selector.insertAfter(n, n.nodes[0])
|
|
17563
|
+
// selector.removeChild(n)
|
|
17564
|
+
// // since slotted attribute already scopes the selector there's no
|
|
17565
|
+
// // need for the non-slot attribute.
|
|
17566
|
+
// shouldInject = false
|
|
17567
|
+
// return false
|
|
17568
|
+
// }
|
|
17348
17569
|
// global: replace with inner selector and do not inject [id].
|
|
17349
17570
|
// ::v-global(.foo) -> .foo
|
|
17350
17571
|
if (value === ':global' || value === '::v-global') {
|
|
@@ -17366,14 +17587,13 @@ function rewriteSelector(id, selector, selectorRoot, slotted = false) {
|
|
|
17366
17587
|
// So all leading spaces must be eliminated to avoid problems.
|
|
17367
17588
|
selector.first.spaces.before = '';
|
|
17368
17589
|
}
|
|
17369
|
-
|
|
17370
|
-
const idToAdd = slotted ? id + '-s' : id;
|
|
17590
|
+
{
|
|
17371
17591
|
selector.insertAfter(
|
|
17372
17592
|
// If node is null it means we need to inject [id] at the start
|
|
17373
17593
|
// insertAfter can handle `null` here
|
|
17374
17594
|
node, selectorParser.attribute({
|
|
17375
|
-
attribute:
|
|
17376
|
-
value:
|
|
17595
|
+
attribute: id,
|
|
17596
|
+
value: id,
|
|
17377
17597
|
raws: {},
|
|
17378
17598
|
quoteMark: `"`
|
|
17379
17599
|
}));
|
|
@@ -17546,12 +17766,13 @@ function compileStyleAsync(options) {
|
|
|
17546
17766
|
return Promise.resolve(doCompileStyle(Object.assign(Object.assign({}, options), { isAsync: true })));
|
|
17547
17767
|
}
|
|
17548
17768
|
function doCompileStyle(options) {
|
|
17549
|
-
const { filename, id, scoped = true, trim = true, preprocessLang, postcssOptions, postcssPlugins } = options;
|
|
17769
|
+
const { filename, id, scoped = true, trim = true, isProd = false, preprocessLang, postcssOptions, postcssPlugins } = options;
|
|
17550
17770
|
const preprocessor = preprocessLang && processors[preprocessLang];
|
|
17551
17771
|
const preProcessedSource = preprocessor && preprocess(options, preprocessor);
|
|
17552
17772
|
const map = preProcessedSource ? preProcessedSource.map : options.map;
|
|
17553
17773
|
const source = preProcessedSource ? preProcessedSource.code : options.source;
|
|
17554
17774
|
const plugins = (postcssPlugins || []).slice();
|
|
17775
|
+
plugins.unshift(cssVarsPlugin({ id: id.replace(/^data-v-/, ''), isProd }));
|
|
17555
17776
|
if (trim) {
|
|
17556
17777
|
plugins.push(trimPlugin());
|
|
17557
17778
|
}
|
|
@@ -17609,94 +17830,6 @@ function preprocess(options, preprocessor) {
|
|
|
17609
17830
|
}, options.preprocessOptions));
|
|
17610
17831
|
}
|
|
17611
17832
|
|
|
17612
|
-
const defaultExportRE = /((?:^|\n|;)\s*)export(\s*)default/;
|
|
17613
|
-
const namedDefaultExportRE = /((?:^|\n|;)\s*)export(.+)(?:as)?(\s*)default/s;
|
|
17614
|
-
const exportDefaultClassRE = /((?:^|\n|;)\s*)export\s+default\s+class\s+([\w$]+)/;
|
|
17615
|
-
/**
|
|
17616
|
-
* Utility for rewriting `export default` in a script block into a variable
|
|
17617
|
-
* declaration so that we can inject things into it
|
|
17618
|
-
*/
|
|
17619
|
-
function rewriteDefault(input, as, parserPlugins) {
|
|
17620
|
-
if (!hasDefaultExport(input)) {
|
|
17621
|
-
return input + `\nconst ${as} = {}`;
|
|
17622
|
-
}
|
|
17623
|
-
let replaced;
|
|
17624
|
-
const classMatch = input.match(exportDefaultClassRE);
|
|
17625
|
-
if (classMatch) {
|
|
17626
|
-
replaced =
|
|
17627
|
-
input.replace(exportDefaultClassRE, '$1class $2') +
|
|
17628
|
-
`\nconst ${as} = ${classMatch[2]}`;
|
|
17629
|
-
}
|
|
17630
|
-
else {
|
|
17631
|
-
replaced = input.replace(defaultExportRE, `$1const ${as} =`);
|
|
17632
|
-
}
|
|
17633
|
-
if (!hasDefaultExport(replaced)) {
|
|
17634
|
-
return replaced;
|
|
17635
|
-
}
|
|
17636
|
-
// if the script somehow still contains `default export`, it probably has
|
|
17637
|
-
// multi-line comments or template strings. fallback to a full parse.
|
|
17638
|
-
const s = new MagicString(input);
|
|
17639
|
-
const ast = parser$1.parse(input, {
|
|
17640
|
-
sourceType: 'module',
|
|
17641
|
-
plugins: parserPlugins
|
|
17642
|
-
}).program.body;
|
|
17643
|
-
ast.forEach(node => {
|
|
17644
|
-
if (node.type === 'ExportDefaultDeclaration') {
|
|
17645
|
-
s.overwrite(node.start, node.declaration.start, `const ${as} = `);
|
|
17646
|
-
}
|
|
17647
|
-
if (node.type === 'ExportNamedDeclaration') {
|
|
17648
|
-
for (const specifier of node.specifiers) {
|
|
17649
|
-
if (specifier.type === 'ExportSpecifier' &&
|
|
17650
|
-
specifier.exported.type === 'Identifier' &&
|
|
17651
|
-
specifier.exported.name === 'default') {
|
|
17652
|
-
if (node.source) {
|
|
17653
|
-
if (specifier.local.name === 'default') {
|
|
17654
|
-
const end = specifierEnd(input, specifier.local.end, node.end);
|
|
17655
|
-
s.prepend(`import { default as __VUE_DEFAULT__ } from '${node.source.value}'\n`);
|
|
17656
|
-
s.overwrite(specifier.start, end, ``);
|
|
17657
|
-
s.append(`\nconst ${as} = __VUE_DEFAULT__`);
|
|
17658
|
-
continue;
|
|
17659
|
-
}
|
|
17660
|
-
else {
|
|
17661
|
-
const end = specifierEnd(input, specifier.exported.end, node.end);
|
|
17662
|
-
s.prepend(`import { ${input.slice(specifier.local.start, specifier.local.end)} } from '${node.source.value}'\n`);
|
|
17663
|
-
s.overwrite(specifier.start, end, ``);
|
|
17664
|
-
s.append(`\nconst ${as} = ${specifier.local.name}`);
|
|
17665
|
-
continue;
|
|
17666
|
-
}
|
|
17667
|
-
}
|
|
17668
|
-
const end = specifierEnd(input, specifier.end, node.end);
|
|
17669
|
-
s.overwrite(specifier.start, end, ``);
|
|
17670
|
-
s.append(`\nconst ${as} = ${specifier.local.name}`);
|
|
17671
|
-
}
|
|
17672
|
-
}
|
|
17673
|
-
}
|
|
17674
|
-
});
|
|
17675
|
-
return s.toString();
|
|
17676
|
-
}
|
|
17677
|
-
function hasDefaultExport(input) {
|
|
17678
|
-
return defaultExportRE.test(input) || namedDefaultExportRE.test(input);
|
|
17679
|
-
}
|
|
17680
|
-
function specifierEnd(input, end, nodeEnd) {
|
|
17681
|
-
// export { default , foo } ...
|
|
17682
|
-
let hasCommas = false;
|
|
17683
|
-
let oldEnd = end;
|
|
17684
|
-
while (end < nodeEnd) {
|
|
17685
|
-
if (/\s/.test(input.charAt(end))) {
|
|
17686
|
-
end++;
|
|
17687
|
-
}
|
|
17688
|
-
else if (input.charAt(end) === ',') {
|
|
17689
|
-
end++;
|
|
17690
|
-
hasCommas = true;
|
|
17691
|
-
break;
|
|
17692
|
-
}
|
|
17693
|
-
else if (input.charAt(end) === '}') {
|
|
17694
|
-
break;
|
|
17695
|
-
}
|
|
17696
|
-
}
|
|
17697
|
-
return hasCommas ? end : oldEnd;
|
|
17698
|
-
}
|
|
17699
|
-
|
|
17700
17833
|
exports.compileScript = compileScript;
|
|
17701
17834
|
exports.compileStyle = compileStyle;
|
|
17702
17835
|
exports.compileStyleAsync = compileStyleAsync;
|