v0.1
This commit is contained in:
commit
4aaaf23d2f
2411 files changed
+1248679
No files matched your search
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2018-present, Yuxi (Evan) You
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
+1
@@ -0,0 +1 @@
|
||||
# @vue/compiler-core
|
||||
+6888
File diff suppressed because it is too large.
Load diff
+6763
File diff suppressed because it is too large.
Load diff
+1100
File diff suppressed because it is too large.
Load diff
+5835
File diff suppressed because it is too large.
Load diff
+7
@@ -0,0 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
module.exports = require('./dist/compiler-core.cjs.prod.js')
|
||||
} else {
|
||||
module.exports = require('./dist/compiler-core.cjs.js')
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
{
|
||||
"name": "@vue/compiler-core",
|
||||
"version": "3.5.30",
|
||||
"description": "@vue/compiler-core",
|
||||
"main": "index.js",
|
||||
"module": "dist/compiler-core.esm-bundler.js",
|
||||
"types": "dist/compiler-core.d.ts",
|
||||
"files": [
|
||||
"index.js",
|
||||
"dist"
|
||||
],
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/compiler-core.d.ts",
|
||||
"node": {
|
||||
"production": "./dist/compiler-core.cjs.prod.js",
|
||||
"development": "./dist/compiler-core.cjs.js",
|
||||
"default": "./index.js"
|
||||
},
|
||||
"module": "./dist/compiler-core.esm-bundler.js",
|
||||
"import": "./dist/compiler-core.esm-bundler.js",
|
||||
"require": "./index.js"
|
||||
},
|
||||
"./*": "./*"
|
||||
},
|
||||
"buildOptions": {
|
||||
"name": "VueCompilerCore",
|
||||
"compat": true,
|
||||
"formats": [
|
||||
"esm-bundler",
|
||||
"cjs"
|
||||
]
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/vuejs/core.git",
|
||||
"directory": "packages/compiler-core"
|
||||
},
|
||||
"keywords": [
|
||||
"vue"
|
||||
],
|
||||
"author": "Evan You",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/vuejs/core/issues"
|
||||
},
|
||||
"homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-core#readme",
|
||||
"dependencies": {
|
||||
"@babel/parser": "^7.29.0",
|
||||
"entities": "^7.0.1",
|
||||
"estree-walker": "^2.0.2",
|
||||
"source-map-js": "^1.2.1",
|
||||
"@vue/shared": "3.5.30"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/types": "^7.29.0"
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2018-present, Yuxi (Evan) You
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
+1
@@ -0,0 +1 @@
|
||||
# @vue/compiler-dom
|
||||
+934
@@ -0,0 +1,934 @@
|
||||
/**
|
||||
* @vue/compiler-dom v3.5.30
|
||||
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
||||
* @license MIT
|
||||
**/
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
var compilerCore = require('@vue/compiler-core');
|
||||
var shared = require('@vue/shared');
|
||||
|
||||
const V_MODEL_RADIO = /* @__PURE__ */ Symbol(`vModelRadio` );
|
||||
const V_MODEL_CHECKBOX = /* @__PURE__ */ Symbol(
|
||||
`vModelCheckbox`
|
||||
);
|
||||
const V_MODEL_TEXT = /* @__PURE__ */ Symbol(`vModelText` );
|
||||
const V_MODEL_SELECT = /* @__PURE__ */ Symbol(
|
||||
`vModelSelect`
|
||||
);
|
||||
const V_MODEL_DYNAMIC = /* @__PURE__ */ Symbol(
|
||||
`vModelDynamic`
|
||||
);
|
||||
const V_ON_WITH_MODIFIERS = /* @__PURE__ */ Symbol(
|
||||
`vOnModifiersGuard`
|
||||
);
|
||||
const V_ON_WITH_KEYS = /* @__PURE__ */ Symbol(
|
||||
`vOnKeysGuard`
|
||||
);
|
||||
const V_SHOW = /* @__PURE__ */ Symbol(`vShow` );
|
||||
const TRANSITION = /* @__PURE__ */ Symbol(`Transition` );
|
||||
const TRANSITION_GROUP = /* @__PURE__ */ Symbol(
|
||||
`TransitionGroup`
|
||||
);
|
||||
compilerCore.registerRuntimeHelpers({
|
||||
[V_MODEL_RADIO]: `vModelRadio`,
|
||||
[V_MODEL_CHECKBOX]: `vModelCheckbox`,
|
||||
[V_MODEL_TEXT]: `vModelText`,
|
||||
[V_MODEL_SELECT]: `vModelSelect`,
|
||||
[V_MODEL_DYNAMIC]: `vModelDynamic`,
|
||||
[V_ON_WITH_MODIFIERS]: `withModifiers`,
|
||||
[V_ON_WITH_KEYS]: `withKeys`,
|
||||
[V_SHOW]: `vShow`,
|
||||
[TRANSITION]: `Transition`,
|
||||
[TRANSITION_GROUP]: `TransitionGroup`
|
||||
});
|
||||
|
||||
const parserOptions = {
|
||||
parseMode: "html",
|
||||
isVoidTag: shared.isVoidTag,
|
||||
isNativeTag: (tag) => shared.isHTMLTag(tag) || shared.isSVGTag(tag) || shared.isMathMLTag(tag),
|
||||
isPreTag: (tag) => tag === "pre",
|
||||
isIgnoreNewlineTag: (tag) => tag === "pre" || tag === "textarea",
|
||||
decodeEntities: void 0,
|
||||
isBuiltInComponent: (tag) => {
|
||||
if (tag === "Transition" || tag === "transition") {
|
||||
return TRANSITION;
|
||||
} else if (tag === "TransitionGroup" || tag === "transition-group") {
|
||||
return TRANSITION_GROUP;
|
||||
}
|
||||
},
|
||||
// https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
|
||||
getNamespace(tag, parent, rootNamespace) {
|
||||
let ns = parent ? parent.ns : rootNamespace;
|
||||
if (parent && ns === 2) {
|
||||
if (parent.tag === "annotation-xml") {
|
||||
if (tag === "svg") {
|
||||
return 1;
|
||||
}
|
||||
if (parent.props.some(
|
||||
(a) => a.type === 6 && a.name === "encoding" && a.value != null && (a.value.content === "text/html" || a.value.content === "application/xhtml+xml")
|
||||
)) {
|
||||
ns = 0;
|
||||
}
|
||||
} else if (/^m(?:[ions]|text)$/.test(parent.tag) && tag !== "mglyph" && tag !== "malignmark") {
|
||||
ns = 0;
|
||||
}
|
||||
} else if (parent && ns === 1) {
|
||||
if (parent.tag === "foreignObject" || parent.tag === "desc" || parent.tag === "title") {
|
||||
ns = 0;
|
||||
}
|
||||
}
|
||||
if (ns === 0) {
|
||||
if (tag === "svg") {
|
||||
return 1;
|
||||
}
|
||||
if (tag === "math") {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
return ns;
|
||||
}
|
||||
};
|
||||
|
||||
const transformStyle = (node) => {
|
||||
if (node.type === 1) {
|
||||
node.props.forEach((p, i) => {
|
||||
if (p.type === 6 && p.name === "style" && p.value) {
|
||||
node.props[i] = {
|
||||
type: 7,
|
||||
name: `bind`,
|
||||
arg: compilerCore.createSimpleExpression(`style`, true, p.loc),
|
||||
exp: parseInlineCSS(p.value.content, p.loc),
|
||||
modifiers: [],
|
||||
loc: p.loc
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
const parseInlineCSS = (cssText, loc) => {
|
||||
const normalized = shared.parseStringStyle(cssText);
|
||||
return compilerCore.createSimpleExpression(
|
||||
JSON.stringify(normalized),
|
||||
false,
|
||||
loc,
|
||||
3
|
||||
);
|
||||
};
|
||||
|
||||
function createDOMCompilerError(code, loc) {
|
||||
return compilerCore.createCompilerError(
|
||||
code,
|
||||
loc,
|
||||
DOMErrorMessages
|
||||
);
|
||||
}
|
||||
const DOMErrorCodes = {
|
||||
"X_V_HTML_NO_EXPRESSION": 54,
|
||||
"54": "X_V_HTML_NO_EXPRESSION",
|
||||
"X_V_HTML_WITH_CHILDREN": 55,
|
||||
"55": "X_V_HTML_WITH_CHILDREN",
|
||||
"X_V_TEXT_NO_EXPRESSION": 56,
|
||||
"56": "X_V_TEXT_NO_EXPRESSION",
|
||||
"X_V_TEXT_WITH_CHILDREN": 57,
|
||||
"57": "X_V_TEXT_WITH_CHILDREN",
|
||||
"X_V_MODEL_ON_INVALID_ELEMENT": 58,
|
||||
"58": "X_V_MODEL_ON_INVALID_ELEMENT",
|
||||
"X_V_MODEL_ARG_ON_ELEMENT": 59,
|
||||
"59": "X_V_MODEL_ARG_ON_ELEMENT",
|
||||
"X_V_MODEL_ON_FILE_INPUT_ELEMENT": 60,
|
||||
"60": "X_V_MODEL_ON_FILE_INPUT_ELEMENT",
|
||||
"X_V_MODEL_UNNECESSARY_VALUE": 61,
|
||||
"61": "X_V_MODEL_UNNECESSARY_VALUE",
|
||||
"X_V_SHOW_NO_EXPRESSION": 62,
|
||||
"62": "X_V_SHOW_NO_EXPRESSION",
|
||||
"X_TRANSITION_INVALID_CHILDREN": 63,
|
||||
"63": "X_TRANSITION_INVALID_CHILDREN",
|
||||
"X_IGNORED_SIDE_EFFECT_TAG": 64,
|
||||
"64": "X_IGNORED_SIDE_EFFECT_TAG",
|
||||
"__EXTEND_POINT__": 65,
|
||||
"65": "__EXTEND_POINT__"
|
||||
};
|
||||
const DOMErrorMessages = {
|
||||
[54]: `v-html is missing expression.`,
|
||||
[55]: `v-html will override element children.`,
|
||||
[56]: `v-text is missing expression.`,
|
||||
[57]: `v-text will override element children.`,
|
||||
[58]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
|
||||
[59]: `v-model argument is not supported on plain elements.`,
|
||||
[60]: `v-model cannot be used on file inputs since they are read-only. Use a v-on:change listener instead.`,
|
||||
[61]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
|
||||
[62]: `v-show is missing expression.`,
|
||||
[63]: `<Transition> expects exactly one child element or component.`,
|
||||
[64]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
|
||||
};
|
||||
|
||||
const transformVHtml = (dir, node, context) => {
|
||||
const { exp, loc } = dir;
|
||||
if (!exp) {
|
||||
context.onError(
|
||||
createDOMCompilerError(54, loc)
|
||||
);
|
||||
}
|
||||
if (node.children.length) {
|
||||
context.onError(
|
||||
createDOMCompilerError(55, loc)
|
||||
);
|
||||
node.children.length = 0;
|
||||
}
|
||||
return {
|
||||
props: [
|
||||
compilerCore.createObjectProperty(
|
||||
compilerCore.createSimpleExpression(`innerHTML`, true, loc),
|
||||
exp || compilerCore.createSimpleExpression("", true)
|
||||
)
|
||||
]
|
||||
};
|
||||
};
|
||||
|
||||
const transformVText = (dir, node, context) => {
|
||||
const { exp, loc } = dir;
|
||||
if (!exp) {
|
||||
context.onError(
|
||||
createDOMCompilerError(56, loc)
|
||||
);
|
||||
}
|
||||
if (node.children.length) {
|
||||
context.onError(
|
||||
createDOMCompilerError(57, loc)
|
||||
);
|
||||
node.children.length = 0;
|
||||
}
|
||||
return {
|
||||
props: [
|
||||
compilerCore.createObjectProperty(
|
||||
compilerCore.createSimpleExpression(`textContent`, true),
|
||||
exp ? compilerCore.getConstantType(exp, context) > 0 ? exp : compilerCore.createCallExpression(
|
||||
context.helperString(compilerCore.TO_DISPLAY_STRING),
|
||||
[exp],
|
||||
loc
|
||||
) : compilerCore.createSimpleExpression("", true)
|
||||
)
|
||||
]
|
||||
};
|
||||
};
|
||||
|
||||
const transformModel = (dir, node, context) => {
|
||||
const baseResult = compilerCore.transformModel(dir, node, context);
|
||||
if (!baseResult.props.length || node.tagType === 1) {
|
||||
return baseResult;
|
||||
}
|
||||
if (dir.arg) {
|
||||
context.onError(
|
||||
createDOMCompilerError(
|
||||
59,
|
||||
dir.arg.loc
|
||||
)
|
||||
);
|
||||
}
|
||||
function checkDuplicatedValue() {
|
||||
const value = compilerCore.findDir(node, "bind");
|
||||
if (value && compilerCore.isStaticArgOf(value.arg, "value")) {
|
||||
context.onError(
|
||||
createDOMCompilerError(
|
||||
61,
|
||||
value.loc
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
const { tag } = node;
|
||||
const isCustomElement = context.isCustomElement(tag);
|
||||
if (tag === "input" || tag === "textarea" || tag === "select" || isCustomElement) {
|
||||
let directiveToUse = V_MODEL_TEXT;
|
||||
let isInvalidType = false;
|
||||
if (tag === "input" || isCustomElement) {
|
||||
const type = compilerCore.findProp(node, `type`);
|
||||
if (type) {
|
||||
if (type.type === 7) {
|
||||
directiveToUse = V_MODEL_DYNAMIC;
|
||||
} else if (type.value) {
|
||||
switch (type.value.content) {
|
||||
case "radio":
|
||||
directiveToUse = V_MODEL_RADIO;
|
||||
break;
|
||||
case "checkbox":
|
||||
directiveToUse = V_MODEL_CHECKBOX;
|
||||
break;
|
||||
case "file":
|
||||
isInvalidType = true;
|
||||
context.onError(
|
||||
createDOMCompilerError(
|
||||
60,
|
||||
dir.loc
|
||||
)
|
||||
);
|
||||
break;
|
||||
default:
|
||||
checkDuplicatedValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (compilerCore.hasDynamicKeyVBind(node)) {
|
||||
directiveToUse = V_MODEL_DYNAMIC;
|
||||
} else {
|
||||
checkDuplicatedValue();
|
||||
}
|
||||
} else if (tag === "select") {
|
||||
directiveToUse = V_MODEL_SELECT;
|
||||
} else {
|
||||
checkDuplicatedValue();
|
||||
}
|
||||
if (!isInvalidType) {
|
||||
baseResult.needRuntime = context.helper(directiveToUse);
|
||||
}
|
||||
} else {
|
||||
context.onError(
|
||||
createDOMCompilerError(
|
||||
58,
|
||||
dir.loc
|
||||
)
|
||||
);
|
||||
}
|
||||
baseResult.props = baseResult.props.filter(
|
||||
(p) => !(p.key.type === 4 && p.key.content === "modelValue")
|
||||
);
|
||||
return baseResult;
|
||||
};
|
||||
|
||||
const isEventOptionModifier = /* @__PURE__ */ shared.makeMap(`passive,once,capture`);
|
||||
const isNonKeyModifier = /* @__PURE__ */ shared.makeMap(
|
||||
// event propagation management
|
||||
`stop,prevent,self,ctrl,shift,alt,meta,exact,middle`
|
||||
);
|
||||
const maybeKeyModifier = /* @__PURE__ */ shared.makeMap("left,right");
|
||||
const isKeyboardEvent = /* @__PURE__ */ shared.makeMap(`onkeyup,onkeydown,onkeypress`);
|
||||
const resolveModifiers = (key, modifiers, context, loc) => {
|
||||
const keyModifiers = [];
|
||||
const nonKeyModifiers = [];
|
||||
const eventOptionModifiers = [];
|
||||
for (let i = 0; i < modifiers.length; i++) {
|
||||
const modifier = modifiers[i].content;
|
||||
if (modifier === "native" && compilerCore.checkCompatEnabled(
|
||||
"COMPILER_V_ON_NATIVE",
|
||||
context,
|
||||
loc
|
||||
)) {
|
||||
eventOptionModifiers.push(modifier);
|
||||
} else if (isEventOptionModifier(modifier)) {
|
||||
eventOptionModifiers.push(modifier);
|
||||
} else {
|
||||
if (maybeKeyModifier(modifier)) {
|
||||
if (compilerCore.isStaticExp(key)) {
|
||||
if (isKeyboardEvent(key.content.toLowerCase())) {
|
||||
keyModifiers.push(modifier);
|
||||
} else {
|
||||
nonKeyModifiers.push(modifier);
|
||||
}
|
||||
} else {
|
||||
keyModifiers.push(modifier);
|
||||
nonKeyModifiers.push(modifier);
|
||||
}
|
||||
} else {
|
||||
if (isNonKeyModifier(modifier)) {
|
||||
nonKeyModifiers.push(modifier);
|
||||
} else {
|
||||
keyModifiers.push(modifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
keyModifiers,
|
||||
nonKeyModifiers,
|
||||
eventOptionModifiers
|
||||
};
|
||||
};
|
||||
const transformClick = (key, event) => {
|
||||
const isStaticClick = compilerCore.isStaticExp(key) && key.content.toLowerCase() === "onclick";
|
||||
return isStaticClick ? compilerCore.createSimpleExpression(event, true) : key.type !== 4 ? compilerCore.createCompoundExpression([
|
||||
`(`,
|
||||
key,
|
||||
`) === "onClick" ? "${event}" : (`,
|
||||
key,
|
||||
`)`
|
||||
]) : key;
|
||||
};
|
||||
const transformOn = (dir, node, context) => {
|
||||
return compilerCore.transformOn(dir, node, context, (baseResult) => {
|
||||
const { modifiers } = dir;
|
||||
if (!modifiers.length) return baseResult;
|
||||
let { key, value: handlerExp } = baseResult.props[0];
|
||||
const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
|
||||
if (nonKeyModifiers.includes("right")) {
|
||||
key = transformClick(key, `onContextmenu`);
|
||||
}
|
||||
if (nonKeyModifiers.includes("middle")) {
|
||||
key = transformClick(key, `onMouseup`);
|
||||
}
|
||||
if (nonKeyModifiers.length) {
|
||||
handlerExp = compilerCore.createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
|
||||
handlerExp,
|
||||
JSON.stringify(nonKeyModifiers)
|
||||
]);
|
||||
}
|
||||
if (keyModifiers.length && // if event name is dynamic, always wrap with keys guard
|
||||
(!compilerCore.isStaticExp(key) || isKeyboardEvent(key.content.toLowerCase()))) {
|
||||
handlerExp = compilerCore.createCallExpression(context.helper(V_ON_WITH_KEYS), [
|
||||
handlerExp,
|
||||
JSON.stringify(keyModifiers)
|
||||
]);
|
||||
}
|
||||
if (eventOptionModifiers.length) {
|
||||
const modifierPostfix = eventOptionModifiers.map(shared.capitalize).join("");
|
||||
key = compilerCore.isStaticExp(key) ? compilerCore.createSimpleExpression(`${key.content}${modifierPostfix}`, true) : compilerCore.createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
|
||||
}
|
||||
return {
|
||||
props: [compilerCore.createObjectProperty(key, handlerExp)]
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
const transformShow = (dir, node, context) => {
|
||||
const { exp, loc } = dir;
|
||||
if (!exp) {
|
||||
context.onError(
|
||||
createDOMCompilerError(62, loc)
|
||||
);
|
||||
}
|
||||
return {
|
||||
props: [],
|
||||
needRuntime: context.helper(V_SHOW)
|
||||
};
|
||||
};
|
||||
|
||||
const transformTransition = (node, context) => {
|
||||
if (node.type === 1 && node.tagType === 1) {
|
||||
const component = context.isBuiltInComponent(node.tag);
|
||||
if (component === TRANSITION) {
|
||||
return () => {
|
||||
if (!node.children.length) {
|
||||
return;
|
||||
}
|
||||
if (hasMultipleChildren(node)) {
|
||||
context.onError(
|
||||
createDOMCompilerError(
|
||||
63,
|
||||
{
|
||||
start: node.children[0].loc.start,
|
||||
end: node.children[node.children.length - 1].loc.end,
|
||||
source: ""
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
const child = node.children[0];
|
||||
if (child.type === 1) {
|
||||
for (const p of child.props) {
|
||||
if (p.type === 7 && p.name === "show") {
|
||||
node.props.push({
|
||||
type: 6,
|
||||
name: "persisted",
|
||||
nameLoc: node.loc,
|
||||
value: void 0,
|
||||
loc: node.loc
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
function hasMultipleChildren(node) {
|
||||
const children = node.children = node.children.filter(
|
||||
(c) => !compilerCore.isCommentOrWhitespace(c)
|
||||
);
|
||||
const child = children[0];
|
||||
return children.length !== 1 || child.type === 11 || child.type === 9 && child.branches.some(hasMultipleChildren);
|
||||
}
|
||||
|
||||
const expReplaceRE = /__VUE_EXP_START__(.*?)__VUE_EXP_END__/g;
|
||||
const stringifyStatic = (children, context, parent) => {
|
||||
if (context.scopes.vSlot > 0) {
|
||||
return;
|
||||
}
|
||||
const isParentCached = parent.type === 1 && parent.codegenNode && parent.codegenNode.type === 13 && parent.codegenNode.children && !shared.isArray(parent.codegenNode.children) && parent.codegenNode.children.type === 20;
|
||||
let nc = 0;
|
||||
let ec = 0;
|
||||
const currentChunk = [];
|
||||
const stringifyCurrentChunk = (currentIndex) => {
|
||||
if (nc >= 20 || ec >= 5) {
|
||||
const staticCall = compilerCore.createCallExpression(context.helper(compilerCore.CREATE_STATIC), [
|
||||
JSON.stringify(
|
||||
currentChunk.map((node) => stringifyNode(node, context)).join("")
|
||||
).replace(expReplaceRE, `" + $1 + "`),
|
||||
// the 2nd argument indicates the number of DOM nodes this static vnode
|
||||
// will insert / hydrate
|
||||
String(currentChunk.length)
|
||||
]);
|
||||
const deleteCount = currentChunk.length - 1;
|
||||
if (isParentCached) {
|
||||
children.splice(
|
||||
currentIndex - currentChunk.length,
|
||||
currentChunk.length,
|
||||
// @ts-expect-error
|
||||
staticCall
|
||||
);
|
||||
} else {
|
||||
currentChunk[0].codegenNode.value = staticCall;
|
||||
if (currentChunk.length > 1) {
|
||||
children.splice(currentIndex - currentChunk.length + 1, deleteCount);
|
||||
const cacheIndex = context.cached.indexOf(
|
||||
currentChunk[currentChunk.length - 1].codegenNode
|
||||
);
|
||||
if (cacheIndex > -1) {
|
||||
for (let i2 = cacheIndex; i2 < context.cached.length; i2++) {
|
||||
const c = context.cached[i2];
|
||||
if (c) c.index -= deleteCount;
|
||||
}
|
||||
context.cached.splice(cacheIndex - deleteCount + 1, deleteCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
return deleteCount;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
let i = 0;
|
||||
for (; i < children.length; i++) {
|
||||
const child = children[i];
|
||||
const isCached = isParentCached || getCachedNode(child);
|
||||
if (isCached) {
|
||||
const result = analyzeNode(child);
|
||||
if (result) {
|
||||
nc += result[0];
|
||||
ec += result[1];
|
||||
currentChunk.push(child);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
i -= stringifyCurrentChunk(i);
|
||||
nc = 0;
|
||||
ec = 0;
|
||||
currentChunk.length = 0;
|
||||
}
|
||||
stringifyCurrentChunk(i);
|
||||
};
|
||||
const getCachedNode = (node) => {
|
||||
if ((node.type === 1 && node.tagType === 0 || node.type === 12) && node.codegenNode && node.codegenNode.type === 20) {
|
||||
return node.codegenNode;
|
||||
}
|
||||
};
|
||||
const dataAriaRE = /^(?:data|aria)-/;
|
||||
const isStringifiableAttr = (name, ns) => {
|
||||
return (ns === 0 ? shared.isKnownHtmlAttr(name) : ns === 1 ? shared.isKnownSvgAttr(name) : ns === 2 ? shared.isKnownMathMLAttr(name) : false) || dataAriaRE.test(name);
|
||||
};
|
||||
const isNonStringifiable = /* @__PURE__ */ shared.makeMap(
|
||||
`caption,thead,tr,th,tbody,td,tfoot,colgroup,col`
|
||||
);
|
||||
function analyzeNode(node) {
|
||||
if (node.type === 1 && isNonStringifiable(node.tag)) {
|
||||
return false;
|
||||
}
|
||||
if (node.type === 1 && compilerCore.findDir(node, "once", true)) {
|
||||
return false;
|
||||
}
|
||||
if (node.type === 12) {
|
||||
return [1, 0];
|
||||
}
|
||||
let nc = 1;
|
||||
let ec = node.props.length > 0 ? 1 : 0;
|
||||
let bailed = false;
|
||||
const bail = () => {
|
||||
bailed = true;
|
||||
return false;
|
||||
};
|
||||
function walk(node2) {
|
||||
const isOptionTag = node2.tag === "option" && node2.ns === 0;
|
||||
for (let i = 0; i < node2.props.length; i++) {
|
||||
const p = node2.props[i];
|
||||
if (p.type === 6 && !isStringifiableAttr(p.name, node2.ns)) {
|
||||
return bail();
|
||||
}
|
||||
if (p.type === 7 && p.name === "bind") {
|
||||
if (p.arg && (p.arg.type === 8 || p.arg.isStatic && !isStringifiableAttr(p.arg.content, node2.ns))) {
|
||||
return bail();
|
||||
}
|
||||
if (p.exp && (p.exp.type === 8 || p.exp.constType < 3)) {
|
||||
return bail();
|
||||
}
|
||||
if (isOptionTag && compilerCore.isStaticArgOf(p.arg, "value") && p.exp && !p.exp.isStatic) {
|
||||
return bail();
|
||||
}
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < node2.children.length; i++) {
|
||||
nc++;
|
||||
const child = node2.children[i];
|
||||
if (child.type === 1) {
|
||||
if (child.props.length > 0) {
|
||||
ec++;
|
||||
}
|
||||
walk(child);
|
||||
if (bailed) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return walk(node) ? [nc, ec] : false;
|
||||
}
|
||||
function stringifyNode(node, context) {
|
||||
if (shared.isString(node)) {
|
||||
return node;
|
||||
}
|
||||
if (shared.isSymbol(node)) {
|
||||
return ``;
|
||||
}
|
||||
switch (node.type) {
|
||||
case 1:
|
||||
return stringifyElement(node, context);
|
||||
case 2:
|
||||
return shared.escapeHtml(node.content);
|
||||
case 3:
|
||||
return `<!--${shared.escapeHtml(node.content)}-->`;
|
||||
case 5:
|
||||
return shared.escapeHtml(shared.toDisplayString(evaluateConstant(node.content)));
|
||||
case 8:
|
||||
return shared.escapeHtml(evaluateConstant(node));
|
||||
case 12:
|
||||
return stringifyNode(node.content, context);
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
function stringifyElement(node, context) {
|
||||
let res = `<${node.tag}`;
|
||||
let innerHTML = "";
|
||||
for (let i = 0; i < node.props.length; i++) {
|
||||
const p = node.props[i];
|
||||
if (p.type === 6) {
|
||||
res += ` ${p.name}`;
|
||||
if (p.value) {
|
||||
res += `="${shared.escapeHtml(p.value.content)}"`;
|
||||
}
|
||||
} else if (p.type === 7) {
|
||||
if (p.name === "bind") {
|
||||
const exp = p.exp;
|
||||
if (exp.content[0] === "_") {
|
||||
res += ` ${p.arg.content}="__VUE_EXP_START__${exp.content}__VUE_EXP_END__"`;
|
||||
continue;
|
||||
}
|
||||
if (shared.isBooleanAttr(p.arg.content) && exp.content === "false") {
|
||||
continue;
|
||||
}
|
||||
let evaluated = evaluateConstant(exp);
|
||||
if (evaluated != null) {
|
||||
const arg = p.arg && p.arg.content;
|
||||
if (arg === "class") {
|
||||
evaluated = shared.normalizeClass(evaluated);
|
||||
} else if (arg === "style") {
|
||||
evaluated = shared.stringifyStyle(shared.normalizeStyle(evaluated));
|
||||
}
|
||||
res += ` ${p.arg.content}="${shared.escapeHtml(
|
||||
evaluated
|
||||
)}"`;
|
||||
}
|
||||
} else if (p.name === "html") {
|
||||
innerHTML = evaluateConstant(p.exp);
|
||||
} else if (p.name === "text") {
|
||||
innerHTML = shared.escapeHtml(
|
||||
shared.toDisplayString(evaluateConstant(p.exp))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (context.scopeId) {
|
||||
res += ` ${context.scopeId}`;
|
||||
}
|
||||
res += `>`;
|
||||
if (innerHTML) {
|
||||
res += innerHTML;
|
||||
} else {
|
||||
for (let i = 0; i < node.children.length; i++) {
|
||||
res += stringifyNode(node.children[i], context);
|
||||
}
|
||||
}
|
||||
if (!shared.isVoidTag(node.tag)) {
|
||||
res += `</${node.tag}>`;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
function evaluateConstant(exp) {
|
||||
if (exp.type === 4) {
|
||||
return new Function(`return (${exp.content})`)();
|
||||
} else {
|
||||
let res = ``;
|
||||
exp.children.forEach((c) => {
|
||||
if (shared.isString(c) || shared.isSymbol(c)) {
|
||||
return;
|
||||
}
|
||||
if (c.type === 2) {
|
||||
res += c.content;
|
||||
} else if (c.type === 5) {
|
||||
res += shared.toDisplayString(evaluateConstant(c.content));
|
||||
} else {
|
||||
res += evaluateConstant(c);
|
||||
}
|
||||
});
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
const ignoreSideEffectTags = (node, context) => {
|
||||
if (node.type === 1 && node.tagType === 0 && (node.tag === "script" || node.tag === "style")) {
|
||||
context.onError(
|
||||
createDOMCompilerError(
|
||||
64,
|
||||
node.loc
|
||||
)
|
||||
);
|
||||
context.removeNode();
|
||||
}
|
||||
};
|
||||
|
||||
function isValidHTMLNesting(parent, child) {
|
||||
if (parent === "template") {
|
||||
return true;
|
||||
}
|
||||
if (parent in onlyValidChildren) {
|
||||
return onlyValidChildren[parent].has(child);
|
||||
}
|
||||
if (child in onlyValidParents) {
|
||||
return onlyValidParents[child].has(parent);
|
||||
}
|
||||
if (parent in knownInvalidChildren) {
|
||||
if (knownInvalidChildren[parent].has(child)) return false;
|
||||
}
|
||||
if (child in knownInvalidParents) {
|
||||
if (knownInvalidParents[child].has(parent)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
const headings = /* @__PURE__ */ new Set(["h1", "h2", "h3", "h4", "h5", "h6"]);
|
||||
const emptySet = /* @__PURE__ */ new Set([]);
|
||||
const onlyValidChildren = {
|
||||
head: /* @__PURE__ */ new Set([
|
||||
"base",
|
||||
"basefront",
|
||||
"bgsound",
|
||||
"link",
|
||||
"meta",
|
||||
"title",
|
||||
"noscript",
|
||||
"noframes",
|
||||
"style",
|
||||
"script",
|
||||
"template"
|
||||
]),
|
||||
optgroup: /* @__PURE__ */ new Set(["option"]),
|
||||
select: /* @__PURE__ */ new Set(["optgroup", "option", "hr"]),
|
||||
// table
|
||||
table: /* @__PURE__ */ new Set(["caption", "colgroup", "tbody", "tfoot", "thead"]),
|
||||
tr: /* @__PURE__ */ new Set(["td", "th"]),
|
||||
colgroup: /* @__PURE__ */ new Set(["col"]),
|
||||
tbody: /* @__PURE__ */ new Set(["tr"]),
|
||||
thead: /* @__PURE__ */ new Set(["tr"]),
|
||||
tfoot: /* @__PURE__ */ new Set(["tr"]),
|
||||
// these elements can not have any children elements
|
||||
script: emptySet,
|
||||
iframe: emptySet,
|
||||
option: emptySet,
|
||||
textarea: emptySet,
|
||||
style: emptySet,
|
||||
title: emptySet
|
||||
};
|
||||
const onlyValidParents = {
|
||||
// sections
|
||||
html: emptySet,
|
||||
body: /* @__PURE__ */ new Set(["html"]),
|
||||
head: /* @__PURE__ */ new Set(["html"]),
|
||||
// table
|
||||
td: /* @__PURE__ */ new Set(["tr"]),
|
||||
colgroup: /* @__PURE__ */ new Set(["table"]),
|
||||
caption: /* @__PURE__ */ new Set(["table"]),
|
||||
tbody: /* @__PURE__ */ new Set(["table"]),
|
||||
tfoot: /* @__PURE__ */ new Set(["table"]),
|
||||
col: /* @__PURE__ */ new Set(["colgroup"]),
|
||||
th: /* @__PURE__ */ new Set(["tr"]),
|
||||
thead: /* @__PURE__ */ new Set(["table"]),
|
||||
tr: /* @__PURE__ */ new Set(["tbody", "thead", "tfoot"]),
|
||||
// data list
|
||||
dd: /* @__PURE__ */ new Set(["dl", "div"]),
|
||||
dt: /* @__PURE__ */ new Set(["dl", "div"]),
|
||||
// other
|
||||
figcaption: /* @__PURE__ */ new Set(["figure"]),
|
||||
// li: new Set(["ul", "ol"]),
|
||||
summary: /* @__PURE__ */ new Set(["details"]),
|
||||
area: /* @__PURE__ */ new Set(["map"])
|
||||
};
|
||||
const knownInvalidChildren = {
|
||||
p: /* @__PURE__ */ new Set([
|
||||
"address",
|
||||
"article",
|
||||
"aside",
|
||||
"blockquote",
|
||||
"center",
|
||||
"details",
|
||||
"dialog",
|
||||
"dir",
|
||||
"div",
|
||||
"dl",
|
||||
"fieldset",
|
||||
"figure",
|
||||
"footer",
|
||||
"form",
|
||||
"h1",
|
||||
"h2",
|
||||
"h3",
|
||||
"h4",
|
||||
"h5",
|
||||
"h6",
|
||||
"header",
|
||||
"hgroup",
|
||||
"hr",
|
||||
"li",
|
||||
"main",
|
||||
"nav",
|
||||
"menu",
|
||||
"ol",
|
||||
"p",
|
||||
"pre",
|
||||
"section",
|
||||
"table",
|
||||
"ul"
|
||||
]),
|
||||
svg: /* @__PURE__ */ new Set([
|
||||
"b",
|
||||
"blockquote",
|
||||
"br",
|
||||
"code",
|
||||
"dd",
|
||||
"div",
|
||||
"dl",
|
||||
"dt",
|
||||
"em",
|
||||
"embed",
|
||||
"h1",
|
||||
"h2",
|
||||
"h3",
|
||||
"h4",
|
||||
"h5",
|
||||
"h6",
|
||||
"hr",
|
||||
"i",
|
||||
"img",
|
||||
"li",
|
||||
"menu",
|
||||
"meta",
|
||||
"ol",
|
||||
"p",
|
||||
"pre",
|
||||
"ruby",
|
||||
"s",
|
||||
"small",
|
||||
"span",
|
||||
"strong",
|
||||
"sub",
|
||||
"sup",
|
||||
"table",
|
||||
"u",
|
||||
"ul",
|
||||
"var"
|
||||
])
|
||||
};
|
||||
const knownInvalidParents = {
|
||||
a: /* @__PURE__ */ new Set(["a"]),
|
||||
button: /* @__PURE__ */ new Set(["button"]),
|
||||
dd: /* @__PURE__ */ new Set(["dd", "dt"]),
|
||||
dt: /* @__PURE__ */ new Set(["dd", "dt"]),
|
||||
form: /* @__PURE__ */ new Set(["form"]),
|
||||
li: /* @__PURE__ */ new Set(["li"]),
|
||||
h1: headings,
|
||||
h2: headings,
|
||||
h3: headings,
|
||||
h4: headings,
|
||||
h5: headings,
|
||||
h6: headings
|
||||
};
|
||||
|
||||
const validateHtmlNesting = (node, context) => {
|
||||
if (node.type === 1 && node.tagType === 0 && context.parent && context.parent.type === 1 && context.parent.tagType === 0 && !isValidHTMLNesting(context.parent.tag, node.tag)) {
|
||||
const error = new SyntaxError(
|
||||
`<${node.tag}> cannot be child of <${context.parent.tag}>, according to HTML specifications. This can cause hydration errors or potentially disrupt future functionality.`
|
||||
);
|
||||
error.loc = node.loc;
|
||||
context.onWarn(error);
|
||||
}
|
||||
};
|
||||
|
||||
const DOMNodeTransforms = [
|
||||
transformStyle,
|
||||
...[transformTransition, validateHtmlNesting]
|
||||
];
|
||||
const DOMDirectiveTransforms = {
|
||||
cloak: compilerCore.noopDirectiveTransform,
|
||||
html: transformVHtml,
|
||||
text: transformVText,
|
||||
model: transformModel,
|
||||
// override compiler-core
|
||||
on: transformOn,
|
||||
// override compiler-core
|
||||
show: transformShow
|
||||
};
|
||||
function compile(src, options = {}) {
|
||||
return compilerCore.baseCompile(
|
||||
src,
|
||||
shared.extend({}, parserOptions, options, {
|
||||
nodeTransforms: [
|
||||
// ignore <script> and <tag>
|
||||
// this is not put inside DOMNodeTransforms because that list is used
|
||||
// by compiler-ssr to generate vnode fallback branches
|
||||
ignoreSideEffectTags,
|
||||
...DOMNodeTransforms,
|
||||
...options.nodeTransforms || []
|
||||
],
|
||||
directiveTransforms: shared.extend(
|
||||
{},
|
||||
DOMDirectiveTransforms,
|
||||
options.directiveTransforms || {}
|
||||
),
|
||||
transformHoist: stringifyStatic
|
||||
})
|
||||
);
|
||||
}
|
||||
function parse(template, options = {}) {
|
||||
return compilerCore.baseParse(template, shared.extend({}, parserOptions, options));
|
||||
}
|
||||
|
||||
exports.DOMDirectiveTransforms = DOMDirectiveTransforms;
|
||||
exports.DOMErrorCodes = DOMErrorCodes;
|
||||
exports.DOMErrorMessages = DOMErrorMessages;
|
||||
exports.DOMNodeTransforms = DOMNodeTransforms;
|
||||
exports.TRANSITION = TRANSITION;
|
||||
exports.TRANSITION_GROUP = TRANSITION_GROUP;
|
||||
exports.V_MODEL_CHECKBOX = V_MODEL_CHECKBOX;
|
||||
exports.V_MODEL_DYNAMIC = V_MODEL_DYNAMIC;
|
||||
exports.V_MODEL_RADIO = V_MODEL_RADIO;
|
||||
exports.V_MODEL_SELECT = V_MODEL_SELECT;
|
||||
exports.V_MODEL_TEXT = V_MODEL_TEXT;
|
||||
exports.V_ON_WITH_KEYS = V_ON_WITH_KEYS;
|
||||
exports.V_ON_WITH_MODIFIERS = V_ON_WITH_MODIFIERS;
|
||||
exports.V_SHOW = V_SHOW;
|
||||
exports.compile = compile;
|
||||
exports.createDOMCompilerError = createDOMCompilerError;
|
||||
exports.parse = parse;
|
||||
exports.parserOptions = parserOptions;
|
||||
exports.transformStyle = transformStyle;
|
||||
Object.keys(compilerCore).forEach(function (k) {
|
||||
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = compilerCore[k];
|
||||
});
|
||||
+689
@@ -0,0 +1,689 @@
|
||||
/**
|
||||
* @vue/compiler-dom v3.5.30
|
||||
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
||||
* @license MIT
|
||||
**/
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
var compilerCore = require('@vue/compiler-core');
|
||||
var shared = require('@vue/shared');
|
||||
|
||||
const V_MODEL_RADIO = /* @__PURE__ */ Symbol(``);
|
||||
const V_MODEL_CHECKBOX = /* @__PURE__ */ Symbol(
|
||||
``
|
||||
);
|
||||
const V_MODEL_TEXT = /* @__PURE__ */ Symbol(``);
|
||||
const V_MODEL_SELECT = /* @__PURE__ */ Symbol(
|
||||
``
|
||||
);
|
||||
const V_MODEL_DYNAMIC = /* @__PURE__ */ Symbol(
|
||||
``
|
||||
);
|
||||
const V_ON_WITH_MODIFIERS = /* @__PURE__ */ Symbol(
|
||||
``
|
||||
);
|
||||
const V_ON_WITH_KEYS = /* @__PURE__ */ Symbol(
|
||||
``
|
||||
);
|
||||
const V_SHOW = /* @__PURE__ */ Symbol(``);
|
||||
const TRANSITION = /* @__PURE__ */ Symbol(``);
|
||||
const TRANSITION_GROUP = /* @__PURE__ */ Symbol(
|
||||
``
|
||||
);
|
||||
compilerCore.registerRuntimeHelpers({
|
||||
[V_MODEL_RADIO]: `vModelRadio`,
|
||||
[V_MODEL_CHECKBOX]: `vModelCheckbox`,
|
||||
[V_MODEL_TEXT]: `vModelText`,
|
||||
[V_MODEL_SELECT]: `vModelSelect`,
|
||||
[V_MODEL_DYNAMIC]: `vModelDynamic`,
|
||||
[V_ON_WITH_MODIFIERS]: `withModifiers`,
|
||||
[V_ON_WITH_KEYS]: `withKeys`,
|
||||
[V_SHOW]: `vShow`,
|
||||
[TRANSITION]: `Transition`,
|
||||
[TRANSITION_GROUP]: `TransitionGroup`
|
||||
});
|
||||
|
||||
const parserOptions = {
|
||||
parseMode: "html",
|
||||
isVoidTag: shared.isVoidTag,
|
||||
isNativeTag: (tag) => shared.isHTMLTag(tag) || shared.isSVGTag(tag) || shared.isMathMLTag(tag),
|
||||
isPreTag: (tag) => tag === "pre",
|
||||
isIgnoreNewlineTag: (tag) => tag === "pre" || tag === "textarea",
|
||||
decodeEntities: void 0,
|
||||
isBuiltInComponent: (tag) => {
|
||||
if (tag === "Transition" || tag === "transition") {
|
||||
return TRANSITION;
|
||||
} else if (tag === "TransitionGroup" || tag === "transition-group") {
|
||||
return TRANSITION_GROUP;
|
||||
}
|
||||
},
|
||||
// https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
|
||||
getNamespace(tag, parent, rootNamespace) {
|
||||
let ns = parent ? parent.ns : rootNamespace;
|
||||
if (parent && ns === 2) {
|
||||
if (parent.tag === "annotation-xml") {
|
||||
if (tag === "svg") {
|
||||
return 1;
|
||||
}
|
||||
if (parent.props.some(
|
||||
(a) => a.type === 6 && a.name === "encoding" && a.value != null && (a.value.content === "text/html" || a.value.content === "application/xhtml+xml")
|
||||
)) {
|
||||
ns = 0;
|
||||
}
|
||||
} else if (/^m(?:[ions]|text)$/.test(parent.tag) && tag !== "mglyph" && tag !== "malignmark") {
|
||||
ns = 0;
|
||||
}
|
||||
} else if (parent && ns === 1) {
|
||||
if (parent.tag === "foreignObject" || parent.tag === "desc" || parent.tag === "title") {
|
||||
ns = 0;
|
||||
}
|
||||
}
|
||||
if (ns === 0) {
|
||||
if (tag === "svg") {
|
||||
return 1;
|
||||
}
|
||||
if (tag === "math") {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
return ns;
|
||||
}
|
||||
};
|
||||
|
||||
const transformStyle = (node) => {
|
||||
if (node.type === 1) {
|
||||
node.props.forEach((p, i) => {
|
||||
if (p.type === 6 && p.name === "style" && p.value) {
|
||||
node.props[i] = {
|
||||
type: 7,
|
||||
name: `bind`,
|
||||
arg: compilerCore.createSimpleExpression(`style`, true, p.loc),
|
||||
exp: parseInlineCSS(p.value.content, p.loc),
|
||||
modifiers: [],
|
||||
loc: p.loc
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
const parseInlineCSS = (cssText, loc) => {
|
||||
const normalized = shared.parseStringStyle(cssText);
|
||||
return compilerCore.createSimpleExpression(
|
||||
JSON.stringify(normalized),
|
||||
false,
|
||||
loc,
|
||||
3
|
||||
);
|
||||
};
|
||||
|
||||
function createDOMCompilerError(code, loc) {
|
||||
return compilerCore.createCompilerError(
|
||||
code,
|
||||
loc,
|
||||
DOMErrorMessages
|
||||
);
|
||||
}
|
||||
const DOMErrorCodes = {
|
||||
"X_V_HTML_NO_EXPRESSION": 54,
|
||||
"54": "X_V_HTML_NO_EXPRESSION",
|
||||
"X_V_HTML_WITH_CHILDREN": 55,
|
||||
"55": "X_V_HTML_WITH_CHILDREN",
|
||||
"X_V_TEXT_NO_EXPRESSION": 56,
|
||||
"56": "X_V_TEXT_NO_EXPRESSION",
|
||||
"X_V_TEXT_WITH_CHILDREN": 57,
|
||||
"57": "X_V_TEXT_WITH_CHILDREN",
|
||||
"X_V_MODEL_ON_INVALID_ELEMENT": 58,
|
||||
"58": "X_V_MODEL_ON_INVALID_ELEMENT",
|
||||
"X_V_MODEL_ARG_ON_ELEMENT": 59,
|
||||
"59": "X_V_MODEL_ARG_ON_ELEMENT",
|
||||
"X_V_MODEL_ON_FILE_INPUT_ELEMENT": 60,
|
||||
"60": "X_V_MODEL_ON_FILE_INPUT_ELEMENT",
|
||||
"X_V_MODEL_UNNECESSARY_VALUE": 61,
|
||||
"61": "X_V_MODEL_UNNECESSARY_VALUE",
|
||||
"X_V_SHOW_NO_EXPRESSION": 62,
|
||||
"62": "X_V_SHOW_NO_EXPRESSION",
|
||||
"X_TRANSITION_INVALID_CHILDREN": 63,
|
||||
"63": "X_TRANSITION_INVALID_CHILDREN",
|
||||
"X_IGNORED_SIDE_EFFECT_TAG": 64,
|
||||
"64": "X_IGNORED_SIDE_EFFECT_TAG",
|
||||
"__EXTEND_POINT__": 65,
|
||||
"65": "__EXTEND_POINT__"
|
||||
};
|
||||
const DOMErrorMessages = {
|
||||
[54]: `v-html is missing expression.`,
|
||||
[55]: `v-html will override element children.`,
|
||||
[56]: `v-text is missing expression.`,
|
||||
[57]: `v-text will override element children.`,
|
||||
[58]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
|
||||
[59]: `v-model argument is not supported on plain elements.`,
|
||||
[60]: `v-model cannot be used on file inputs since they are read-only. Use a v-on:change listener instead.`,
|
||||
[61]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
|
||||
[62]: `v-show is missing expression.`,
|
||||
[63]: `<Transition> expects exactly one child element or component.`,
|
||||
[64]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
|
||||
};
|
||||
|
||||
const transformVHtml = (dir, node, context) => {
|
||||
const { exp, loc } = dir;
|
||||
if (!exp) {
|
||||
context.onError(
|
||||
createDOMCompilerError(54, loc)
|
||||
);
|
||||
}
|
||||
if (node.children.length) {
|
||||
context.onError(
|
||||
createDOMCompilerError(55, loc)
|
||||
);
|
||||
node.children.length = 0;
|
||||
}
|
||||
return {
|
||||
props: [
|
||||
compilerCore.createObjectProperty(
|
||||
compilerCore.createSimpleExpression(`innerHTML`, true, loc),
|
||||
exp || compilerCore.createSimpleExpression("", true)
|
||||
)
|
||||
]
|
||||
};
|
||||
};
|
||||
|
||||
const transformVText = (dir, node, context) => {
|
||||
const { exp, loc } = dir;
|
||||
if (!exp) {
|
||||
context.onError(
|
||||
createDOMCompilerError(56, loc)
|
||||
);
|
||||
}
|
||||
if (node.children.length) {
|
||||
context.onError(
|
||||
createDOMCompilerError(57, loc)
|
||||
);
|
||||
node.children.length = 0;
|
||||
}
|
||||
return {
|
||||
props: [
|
||||
compilerCore.createObjectProperty(
|
||||
compilerCore.createSimpleExpression(`textContent`, true),
|
||||
exp ? compilerCore.getConstantType(exp, context) > 0 ? exp : compilerCore.createCallExpression(
|
||||
context.helperString(compilerCore.TO_DISPLAY_STRING),
|
||||
[exp],
|
||||
loc
|
||||
) : compilerCore.createSimpleExpression("", true)
|
||||
)
|
||||
]
|
||||
};
|
||||
};
|
||||
|
||||
const transformModel = (dir, node, context) => {
|
||||
const baseResult = compilerCore.transformModel(dir, node, context);
|
||||
if (!baseResult.props.length || node.tagType === 1) {
|
||||
return baseResult;
|
||||
}
|
||||
if (dir.arg) {
|
||||
context.onError(
|
||||
createDOMCompilerError(
|
||||
59,
|
||||
dir.arg.loc
|
||||
)
|
||||
);
|
||||
}
|
||||
const { tag } = node;
|
||||
const isCustomElement = context.isCustomElement(tag);
|
||||
if (tag === "input" || tag === "textarea" || tag === "select" || isCustomElement) {
|
||||
let directiveToUse = V_MODEL_TEXT;
|
||||
let isInvalidType = false;
|
||||
if (tag === "input" || isCustomElement) {
|
||||
const type = compilerCore.findProp(node, `type`);
|
||||
if (type) {
|
||||
if (type.type === 7) {
|
||||
directiveToUse = V_MODEL_DYNAMIC;
|
||||
} else if (type.value) {
|
||||
switch (type.value.content) {
|
||||
case "radio":
|
||||
directiveToUse = V_MODEL_RADIO;
|
||||
break;
|
||||
case "checkbox":
|
||||
directiveToUse = V_MODEL_CHECKBOX;
|
||||
break;
|
||||
case "file":
|
||||
isInvalidType = true;
|
||||
context.onError(
|
||||
createDOMCompilerError(
|
||||
60,
|
||||
dir.loc
|
||||
)
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (compilerCore.hasDynamicKeyVBind(node)) {
|
||||
directiveToUse = V_MODEL_DYNAMIC;
|
||||
} else ;
|
||||
} else if (tag === "select") {
|
||||
directiveToUse = V_MODEL_SELECT;
|
||||
} else ;
|
||||
if (!isInvalidType) {
|
||||
baseResult.needRuntime = context.helper(directiveToUse);
|
||||
}
|
||||
} else {
|
||||
context.onError(
|
||||
createDOMCompilerError(
|
||||
58,
|
||||
dir.loc
|
||||
)
|
||||
);
|
||||
}
|
||||
baseResult.props = baseResult.props.filter(
|
||||
(p) => !(p.key.type === 4 && p.key.content === "modelValue")
|
||||
);
|
||||
return baseResult;
|
||||
};
|
||||
|
||||
const isEventOptionModifier = /* @__PURE__ */ shared.makeMap(`passive,once,capture`);
|
||||
const isNonKeyModifier = /* @__PURE__ */ shared.makeMap(
|
||||
// event propagation management
|
||||
`stop,prevent,self,ctrl,shift,alt,meta,exact,middle`
|
||||
);
|
||||
const maybeKeyModifier = /* @__PURE__ */ shared.makeMap("left,right");
|
||||
const isKeyboardEvent = /* @__PURE__ */ shared.makeMap(`onkeyup,onkeydown,onkeypress`);
|
||||
const resolveModifiers = (key, modifiers, context, loc) => {
|
||||
const keyModifiers = [];
|
||||
const nonKeyModifiers = [];
|
||||
const eventOptionModifiers = [];
|
||||
for (let i = 0; i < modifiers.length; i++) {
|
||||
const modifier = modifiers[i].content;
|
||||
if (modifier === "native" && compilerCore.checkCompatEnabled(
|
||||
"COMPILER_V_ON_NATIVE",
|
||||
context,
|
||||
loc
|
||||
)) {
|
||||
eventOptionModifiers.push(modifier);
|
||||
} else if (isEventOptionModifier(modifier)) {
|
||||
eventOptionModifiers.push(modifier);
|
||||
} else {
|
||||
if (maybeKeyModifier(modifier)) {
|
||||
if (compilerCore.isStaticExp(key)) {
|
||||
if (isKeyboardEvent(key.content.toLowerCase())) {
|
||||
keyModifiers.push(modifier);
|
||||
} else {
|
||||
nonKeyModifiers.push(modifier);
|
||||
}
|
||||
} else {
|
||||
keyModifiers.push(modifier);
|
||||
nonKeyModifiers.push(modifier);
|
||||
}
|
||||
} else {
|
||||
if (isNonKeyModifier(modifier)) {
|
||||
nonKeyModifiers.push(modifier);
|
||||
} else {
|
||||
keyModifiers.push(modifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
keyModifiers,
|
||||
nonKeyModifiers,
|
||||
eventOptionModifiers
|
||||
};
|
||||
};
|
||||
const transformClick = (key, event) => {
|
||||
const isStaticClick = compilerCore.isStaticExp(key) && key.content.toLowerCase() === "onclick";
|
||||
return isStaticClick ? compilerCore.createSimpleExpression(event, true) : key.type !== 4 ? compilerCore.createCompoundExpression([
|
||||
`(`,
|
||||
key,
|
||||
`) === "onClick" ? "${event}" : (`,
|
||||
key,
|
||||
`)`
|
||||
]) : key;
|
||||
};
|
||||
const transformOn = (dir, node, context) => {
|
||||
return compilerCore.transformOn(dir, node, context, (baseResult) => {
|
||||
const { modifiers } = dir;
|
||||
if (!modifiers.length) return baseResult;
|
||||
let { key, value: handlerExp } = baseResult.props[0];
|
||||
const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
|
||||
if (nonKeyModifiers.includes("right")) {
|
||||
key = transformClick(key, `onContextmenu`);
|
||||
}
|
||||
if (nonKeyModifiers.includes("middle")) {
|
||||
key = transformClick(key, `onMouseup`);
|
||||
}
|
||||
if (nonKeyModifiers.length) {
|
||||
handlerExp = compilerCore.createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
|
||||
handlerExp,
|
||||
JSON.stringify(nonKeyModifiers)
|
||||
]);
|
||||
}
|
||||
if (keyModifiers.length && // if event name is dynamic, always wrap with keys guard
|
||||
(!compilerCore.isStaticExp(key) || isKeyboardEvent(key.content.toLowerCase()))) {
|
||||
handlerExp = compilerCore.createCallExpression(context.helper(V_ON_WITH_KEYS), [
|
||||
handlerExp,
|
||||
JSON.stringify(keyModifiers)
|
||||
]);
|
||||
}
|
||||
if (eventOptionModifiers.length) {
|
||||
const modifierPostfix = eventOptionModifiers.map(shared.capitalize).join("");
|
||||
key = compilerCore.isStaticExp(key) ? compilerCore.createSimpleExpression(`${key.content}${modifierPostfix}`, true) : compilerCore.createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
|
||||
}
|
||||
return {
|
||||
props: [compilerCore.createObjectProperty(key, handlerExp)]
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
const transformShow = (dir, node, context) => {
|
||||
const { exp, loc } = dir;
|
||||
if (!exp) {
|
||||
context.onError(
|
||||
createDOMCompilerError(62, loc)
|
||||
);
|
||||
}
|
||||
return {
|
||||
props: [],
|
||||
needRuntime: context.helper(V_SHOW)
|
||||
};
|
||||
};
|
||||
|
||||
const expReplaceRE = /__VUE_EXP_START__(.*?)__VUE_EXP_END__/g;
|
||||
const stringifyStatic = (children, context, parent) => {
|
||||
if (context.scopes.vSlot > 0) {
|
||||
return;
|
||||
}
|
||||
const isParentCached = parent.type === 1 && parent.codegenNode && parent.codegenNode.type === 13 && parent.codegenNode.children && !shared.isArray(parent.codegenNode.children) && parent.codegenNode.children.type === 20;
|
||||
let nc = 0;
|
||||
let ec = 0;
|
||||
const currentChunk = [];
|
||||
const stringifyCurrentChunk = (currentIndex) => {
|
||||
if (nc >= 20 || ec >= 5) {
|
||||
const staticCall = compilerCore.createCallExpression(context.helper(compilerCore.CREATE_STATIC), [
|
||||
JSON.stringify(
|
||||
currentChunk.map((node) => stringifyNode(node, context)).join("")
|
||||
).replace(expReplaceRE, `" + $1 + "`),
|
||||
// the 2nd argument indicates the number of DOM nodes this static vnode
|
||||
// will insert / hydrate
|
||||
String(currentChunk.length)
|
||||
]);
|
||||
const deleteCount = currentChunk.length - 1;
|
||||
if (isParentCached) {
|
||||
children.splice(
|
||||
currentIndex - currentChunk.length,
|
||||
currentChunk.length,
|
||||
// @ts-expect-error
|
||||
staticCall
|
||||
);
|
||||
} else {
|
||||
currentChunk[0].codegenNode.value = staticCall;
|
||||
if (currentChunk.length > 1) {
|
||||
children.splice(currentIndex - currentChunk.length + 1, deleteCount);
|
||||
const cacheIndex = context.cached.indexOf(
|
||||
currentChunk[currentChunk.length - 1].codegenNode
|
||||
);
|
||||
if (cacheIndex > -1) {
|
||||
for (let i2 = cacheIndex; i2 < context.cached.length; i2++) {
|
||||
const c = context.cached[i2];
|
||||
if (c) c.index -= deleteCount;
|
||||
}
|
||||
context.cached.splice(cacheIndex - deleteCount + 1, deleteCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
return deleteCount;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
let i = 0;
|
||||
for (; i < children.length; i++) {
|
||||
const child = children[i];
|
||||
const isCached = isParentCached || getCachedNode(child);
|
||||
if (isCached) {
|
||||
const result = analyzeNode(child);
|
||||
if (result) {
|
||||
nc += result[0];
|
||||
ec += result[1];
|
||||
currentChunk.push(child);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
i -= stringifyCurrentChunk(i);
|
||||
nc = 0;
|
||||
ec = 0;
|
||||
currentChunk.length = 0;
|
||||
}
|
||||
stringifyCurrentChunk(i);
|
||||
};
|
||||
const getCachedNode = (node) => {
|
||||
if ((node.type === 1 && node.tagType === 0 || node.type === 12) && node.codegenNode && node.codegenNode.type === 20) {
|
||||
return node.codegenNode;
|
||||
}
|
||||
};
|
||||
const dataAriaRE = /^(?:data|aria)-/;
|
||||
const isStringifiableAttr = (name, ns) => {
|
||||
return (ns === 0 ? shared.isKnownHtmlAttr(name) : ns === 1 ? shared.isKnownSvgAttr(name) : ns === 2 ? shared.isKnownMathMLAttr(name) : false) || dataAriaRE.test(name);
|
||||
};
|
||||
const isNonStringifiable = /* @__PURE__ */ shared.makeMap(
|
||||
`caption,thead,tr,th,tbody,td,tfoot,colgroup,col`
|
||||
);
|
||||
function analyzeNode(node) {
|
||||
if (node.type === 1 && isNonStringifiable(node.tag)) {
|
||||
return false;
|
||||
}
|
||||
if (node.type === 1 && compilerCore.findDir(node, "once", true)) {
|
||||
return false;
|
||||
}
|
||||
if (node.type === 12) {
|
||||
return [1, 0];
|
||||
}
|
||||
let nc = 1;
|
||||
let ec = node.props.length > 0 ? 1 : 0;
|
||||
let bailed = false;
|
||||
const bail = () => {
|
||||
bailed = true;
|
||||
return false;
|
||||
};
|
||||
function walk(node2) {
|
||||
const isOptionTag = node2.tag === "option" && node2.ns === 0;
|
||||
for (let i = 0; i < node2.props.length; i++) {
|
||||
const p = node2.props[i];
|
||||
if (p.type === 6 && !isStringifiableAttr(p.name, node2.ns)) {
|
||||
return bail();
|
||||
}
|
||||
if (p.type === 7 && p.name === "bind") {
|
||||
if (p.arg && (p.arg.type === 8 || p.arg.isStatic && !isStringifiableAttr(p.arg.content, node2.ns))) {
|
||||
return bail();
|
||||
}
|
||||
if (p.exp && (p.exp.type === 8 || p.exp.constType < 3)) {
|
||||
return bail();
|
||||
}
|
||||
if (isOptionTag && compilerCore.isStaticArgOf(p.arg, "value") && p.exp && !p.exp.isStatic) {
|
||||
return bail();
|
||||
}
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < node2.children.length; i++) {
|
||||
nc++;
|
||||
const child = node2.children[i];
|
||||
if (child.type === 1) {
|
||||
if (child.props.length > 0) {
|
||||
ec++;
|
||||
}
|
||||
walk(child);
|
||||
if (bailed) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return walk(node) ? [nc, ec] : false;
|
||||
}
|
||||
function stringifyNode(node, context) {
|
||||
if (shared.isString(node)) {
|
||||
return node;
|
||||
}
|
||||
if (shared.isSymbol(node)) {
|
||||
return ``;
|
||||
}
|
||||
switch (node.type) {
|
||||
case 1:
|
||||
return stringifyElement(node, context);
|
||||
case 2:
|
||||
return shared.escapeHtml(node.content);
|
||||
case 3:
|
||||
return `<!--${shared.escapeHtml(node.content)}-->`;
|
||||
case 5:
|
||||
return shared.escapeHtml(shared.toDisplayString(evaluateConstant(node.content)));
|
||||
case 8:
|
||||
return shared.escapeHtml(evaluateConstant(node));
|
||||
case 12:
|
||||
return stringifyNode(node.content, context);
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
function stringifyElement(node, context) {
|
||||
let res = `<${node.tag}`;
|
||||
let innerHTML = "";
|
||||
for (let i = 0; i < node.props.length; i++) {
|
||||
const p = node.props[i];
|
||||
if (p.type === 6) {
|
||||
res += ` ${p.name}`;
|
||||
if (p.value) {
|
||||
res += `="${shared.escapeHtml(p.value.content)}"`;
|
||||
}
|
||||
} else if (p.type === 7) {
|
||||
if (p.name === "bind") {
|
||||
const exp = p.exp;
|
||||
if (exp.content[0] === "_") {
|
||||
res += ` ${p.arg.content}="__VUE_EXP_START__${exp.content}__VUE_EXP_END__"`;
|
||||
continue;
|
||||
}
|
||||
if (shared.isBooleanAttr(p.arg.content) && exp.content === "false") {
|
||||
continue;
|
||||
}
|
||||
let evaluated = evaluateConstant(exp);
|
||||
if (evaluated != null) {
|
||||
const arg = p.arg && p.arg.content;
|
||||
if (arg === "class") {
|
||||
evaluated = shared.normalizeClass(evaluated);
|
||||
} else if (arg === "style") {
|
||||
evaluated = shared.stringifyStyle(shared.normalizeStyle(evaluated));
|
||||
}
|
||||
res += ` ${p.arg.content}="${shared.escapeHtml(
|
||||
evaluated
|
||||
)}"`;
|
||||
}
|
||||
} else if (p.name === "html") {
|
||||
innerHTML = evaluateConstant(p.exp);
|
||||
} else if (p.name === "text") {
|
||||
innerHTML = shared.escapeHtml(
|
||||
shared.toDisplayString(evaluateConstant(p.exp))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (context.scopeId) {
|
||||
res += ` ${context.scopeId}`;
|
||||
}
|
||||
res += `>`;
|
||||
if (innerHTML) {
|
||||
res += innerHTML;
|
||||
} else {
|
||||
for (let i = 0; i < node.children.length; i++) {
|
||||
res += stringifyNode(node.children[i], context);
|
||||
}
|
||||
}
|
||||
if (!shared.isVoidTag(node.tag)) {
|
||||
res += `</${node.tag}>`;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
function evaluateConstant(exp) {
|
||||
if (exp.type === 4) {
|
||||
return new Function(`return (${exp.content})`)();
|
||||
} else {
|
||||
let res = ``;
|
||||
exp.children.forEach((c) => {
|
||||
if (shared.isString(c) || shared.isSymbol(c)) {
|
||||
return;
|
||||
}
|
||||
if (c.type === 2) {
|
||||
res += c.content;
|
||||
} else if (c.type === 5) {
|
||||
res += shared.toDisplayString(evaluateConstant(c.content));
|
||||
} else {
|
||||
res += evaluateConstant(c);
|
||||
}
|
||||
});
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
const ignoreSideEffectTags = (node, context) => {
|
||||
if (node.type === 1 && node.tagType === 0 && (node.tag === "script" || node.tag === "style")) {
|
||||
context.removeNode();
|
||||
}
|
||||
};
|
||||
|
||||
const DOMNodeTransforms = [
|
||||
transformStyle,
|
||||
...[]
|
||||
];
|
||||
const DOMDirectiveTransforms = {
|
||||
cloak: compilerCore.noopDirectiveTransform,
|
||||
html: transformVHtml,
|
||||
text: transformVText,
|
||||
model: transformModel,
|
||||
// override compiler-core
|
||||
on: transformOn,
|
||||
// override compiler-core
|
||||
show: transformShow
|
||||
};
|
||||
function compile(src, options = {}) {
|
||||
return compilerCore.baseCompile(
|
||||
src,
|
||||
shared.extend({}, parserOptions, options, {
|
||||
nodeTransforms: [
|
||||
// ignore <script> and <tag>
|
||||
// this is not put inside DOMNodeTransforms because that list is used
|
||||
// by compiler-ssr to generate vnode fallback branches
|
||||
ignoreSideEffectTags,
|
||||
...DOMNodeTransforms,
|
||||
...options.nodeTransforms || []
|
||||
],
|
||||
directiveTransforms: shared.extend(
|
||||
{},
|
||||
DOMDirectiveTransforms,
|
||||
options.directiveTransforms || {}
|
||||
),
|
||||
transformHoist: stringifyStatic
|
||||
})
|
||||
);
|
||||
}
|
||||
function parse(template, options = {}) {
|
||||
return compilerCore.baseParse(template, shared.extend({}, parserOptions, options));
|
||||
}
|
||||
|
||||
exports.DOMDirectiveTransforms = DOMDirectiveTransforms;
|
||||
exports.DOMErrorCodes = DOMErrorCodes;
|
||||
exports.DOMErrorMessages = DOMErrorMessages;
|
||||
exports.DOMNodeTransforms = DOMNodeTransforms;
|
||||
exports.TRANSITION = TRANSITION;
|
||||
exports.TRANSITION_GROUP = TRANSITION_GROUP;
|
||||
exports.V_MODEL_CHECKBOX = V_MODEL_CHECKBOX;
|
||||
exports.V_MODEL_DYNAMIC = V_MODEL_DYNAMIC;
|
||||
exports.V_MODEL_RADIO = V_MODEL_RADIO;
|
||||
exports.V_MODEL_SELECT = V_MODEL_SELECT;
|
||||
exports.V_MODEL_TEXT = V_MODEL_TEXT;
|
||||
exports.V_ON_WITH_KEYS = V_ON_WITH_KEYS;
|
||||
exports.V_ON_WITH_MODIFIERS = V_ON_WITH_MODIFIERS;
|
||||
exports.V_SHOW = V_SHOW;
|
||||
exports.compile = compile;
|
||||
exports.createDOMCompilerError = createDOMCompilerError;
|
||||
exports.parse = parse;
|
||||
exports.parserOptions = parserOptions;
|
||||
exports.transformStyle = transformStyle;
|
||||
Object.keys(compilerCore).forEach(function (k) {
|
||||
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = compilerCore[k];
|
||||
});
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
import { ParserOptions, NodeTransform, SourceLocation, CompilerError, DirectiveTransform, RootNode, CompilerOptions, CodegenResult } from '@vue/compiler-core';
|
||||
export * from '@vue/compiler-core';
|
||||
|
||||
export declare const parserOptions: ParserOptions;
|
||||
|
||||
export declare const V_MODEL_RADIO: unique symbol;
|
||||
export declare const V_MODEL_CHECKBOX: unique symbol;
|
||||
export declare const V_MODEL_TEXT: unique symbol;
|
||||
export declare const V_MODEL_SELECT: unique symbol;
|
||||
export declare const V_MODEL_DYNAMIC: unique symbol;
|
||||
export declare const V_ON_WITH_MODIFIERS: unique symbol;
|
||||
export declare const V_ON_WITH_KEYS: unique symbol;
|
||||
export declare const V_SHOW: unique symbol;
|
||||
export declare const TRANSITION: unique symbol;
|
||||
export declare const TRANSITION_GROUP: unique symbol;
|
||||
|
||||
export declare const transformStyle: NodeTransform;
|
||||
|
||||
interface DOMCompilerError extends CompilerError {
|
||||
code: DOMErrorCodes;
|
||||
}
|
||||
export declare function createDOMCompilerError(code: DOMErrorCodes, loc?: SourceLocation): DOMCompilerError;
|
||||
export declare enum DOMErrorCodes {
|
||||
X_V_HTML_NO_EXPRESSION = 54,
|
||||
X_V_HTML_WITH_CHILDREN = 55,
|
||||
X_V_TEXT_NO_EXPRESSION = 56,
|
||||
X_V_TEXT_WITH_CHILDREN = 57,
|
||||
X_V_MODEL_ON_INVALID_ELEMENT = 58,
|
||||
X_V_MODEL_ARG_ON_ELEMENT = 59,
|
||||
X_V_MODEL_ON_FILE_INPUT_ELEMENT = 60,
|
||||
X_V_MODEL_UNNECESSARY_VALUE = 61,
|
||||
X_V_SHOW_NO_EXPRESSION = 62,
|
||||
X_TRANSITION_INVALID_CHILDREN = 63,
|
||||
X_IGNORED_SIDE_EFFECT_TAG = 64,
|
||||
__EXTEND_POINT__ = 65
|
||||
}
|
||||
export declare const DOMErrorMessages: {
|
||||
[code: number]: string;
|
||||
};
|
||||
|
||||
export declare const DOMNodeTransforms: NodeTransform[];
|
||||
export declare const DOMDirectiveTransforms: Record<string, DirectiveTransform>;
|
||||
export declare function compile(src: string | RootNode, options?: CompilerOptions): CodegenResult;
|
||||
export declare function parse(template: string, options?: ParserOptions): RootNode;
|
||||
|
||||
+6644
File diff suppressed because it is too large.
Load diff
+14
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* @vue/compiler-dom v3.5.30
|
||||
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
||||
* @license MIT
|
||||
**/let e;function t(e){let t=Object.create(null);for(let n of e.split(","))t[n]=1;return e=>e in t}let n={},i=()=>{},s=()=>!1,r=e=>111===e.charCodeAt(0)&&110===e.charCodeAt(1)&&(e.charCodeAt(2)>122||97>e.charCodeAt(2)),o=Object.assign,a=Array.isArray,l=e=>"string"==typeof e,c=e=>"symbol"==typeof e,h=e=>null!==e&&"object"==typeof e,d=t(",key,ref,ref_for,ref_key,onVnodeBeforeMount,onVnodeMounted,onVnodeBeforeUpdate,onVnodeUpdated,onVnodeBeforeUnmount,onVnodeUnmounted"),p=t("bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text,memo"),u=e=>{let t=Object.create(null);return n=>t[n]||(t[n]=e(n))},f=/-\w/g,E=u(e=>e.replace(f,e=>e.slice(1).toUpperCase())),_=u(e=>e.charAt(0).toUpperCase()+e.slice(1)),m=u(e=>e?`on${_(e)}`:"");function S(e,t=0,n=e.length){if((t=Math.max(0,Math.min(t,e.length)))>(n=Math.max(0,Math.min(n,e.length))))return"";let i=e.split(/(\r?\n)/),s=i.filter((e,t)=>t%2==1);i=i.filter((e,t)=>t%2==0);let r=0,o=[];for(let e=0;e<i.length;e++)if((r+=i[e].length+(s[e]&&s[e].length||0))>=t){for(let a=e-2;a<=e+2||n>r;a++){if(a<0||a>=i.length)continue;let l=a+1;o.push(`${l}${" ".repeat(Math.max(3-String(l).length,0))}| ${i[a]}`);let c=i[a].length,h=s[a]&&s[a].length||0;if(a===e){let e=t-(r-(c+h)),i=Math.max(1,n>r?c-e:n-t);o.push(" | "+" ".repeat(e)+"^".repeat(i))}else if(a>e){if(n>r){let e=Math.max(Math.min(n-r,c),1);o.push(" | "+"^".repeat(e))}r+=c+h}}break}return o.join(`
|
||||
`)}let g=/;(?![^(]*\))/g,T=/:([^]+)/,N=/\/\*[^]*?\*\//g,I=t("html,body,base,head,link,meta,style,title,address,article,aside,footer,header,hgroup,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,output,progress,select,textarea,details,dialog,menu,summary,template,blockquote,iframe,tfoot"),y=t("svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer,feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,feDistantLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,text,textPath,title,tspan,unknown,use,view"),O=t("annotation,annotation-xml,maction,maligngroup,malignmark,math,menclose,merror,mfenced,mfrac,mfraction,mglyph,mi,mlabeledtr,mlongdiv,mmultiscripts,mn,mo,mover,mpadded,mphantom,mprescripts,mroot,mrow,ms,mscarries,mscarry,msgroup,msline,mspace,msqrt,msrow,mstack,mstyle,msub,msubsup,msup,mtable,mtd,mtext,mtr,munder,munderover,none,semantics"),A=t("area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr"),C=Symbol(""),b=Symbol(""),v=Symbol(""),R=Symbol(""),x=Symbol(""),L=Symbol(""),M=Symbol(""),D=Symbol(""),P=Symbol(""),V=Symbol(""),k=Symbol(""),X=Symbol(""),w=Symbol(""),U=Symbol(""),F=Symbol(""),B=Symbol(""),$=Symbol(""),H=Symbol(""),G=Symbol(""),q=Symbol(""),J=Symbol(""),j=Symbol(""),W=Symbol(""),K=Symbol(""),Y=Symbol(""),Q=Symbol(""),z=Symbol(""),Z=Symbol(""),ee=Symbol(""),et=Symbol(""),en=Symbol(""),ei=Symbol(""),es=Symbol(""),er=Symbol(""),eo=Symbol(""),ea=Symbol(""),el=Symbol(""),ec=Symbol(""),eh=Symbol(""),ed={[C]:"Fragment",[b]:"Teleport",[v]:"Suspense",[R]:"KeepAlive",[x]:"BaseTransition",[L]:"openBlock",[M]:"createBlock",[D]:"createElementBlock",[P]:"createVNode",[V]:"createElementVNode",[k]:"createCommentVNode",[X]:"createTextVNode",[w]:"createStaticVNode",[U]:"resolveComponent",[F]:"resolveDynamicComponent",[B]:"resolveDirective",[$]:"resolveFilter",[H]:"withDirectives",[G]:"renderList",[q]:"renderSlot",[J]:"createSlots",[j]:"toDisplayString",[W]:"mergeProps",[K]:"normalizeClass",[Y]:"normalizeStyle",[Q]:"normalizeProps",[z]:"guardReactiveProps",[Z]:"toHandlers",[ee]:"camelize",[et]:"capitalize",[en]:"toHandlerKey",[ei]:"setBlockTracking",[es]:"pushScopeId",[er]:"popScopeId",[eo]:"withCtx",[ea]:"unref",[el]:"isRef",[ec]:"withMemo",[eh]:"isMemoSame"};function ep(e){Object.getOwnPropertySymbols(e).forEach(t=>{ed[t]=e[t]})}let eu={HTML:0,0:"HTML",SVG:1,1:"SVG",MATH_ML:2,2:"MATH_ML"},ef={ROOT:0,0:"ROOT",ELEMENT:1,1:"ELEMENT",TEXT:2,2:"TEXT",COMMENT:3,3:"COMMENT",SIMPLE_EXPRESSION:4,4:"SIMPLE_EXPRESSION",INTERPOLATION:5,5:"INTERPOLATION",ATTRIBUTE:6,6:"ATTRIBUTE",DIRECTIVE:7,7:"DIRECTIVE",COMPOUND_EXPRESSION:8,8:"COMPOUND_EXPRESSION",IF:9,9:"IF",IF_BRANCH:10,10:"IF_BRANCH",FOR:11,11:"FOR",TEXT_CALL:12,12:"TEXT_CALL",VNODE_CALL:13,13:"VNODE_CALL",JS_CALL_EXPRESSION:14,14:"JS_CALL_EXPRESSION",JS_OBJECT_EXPRESSION:15,15:"JS_OBJECT_EXPRESSION",JS_PROPERTY:16,16:"JS_PROPERTY",JS_ARRAY_EXPRESSION:17,17:"JS_ARRAY_EXPRESSION",JS_FUNCTION_EXPRESSION:18,18:"JS_FUNCTION_EXPRESSION",JS_CONDITIONAL_EXPRESSION:19,19:"JS_CONDITIONAL_EXPRESSION",JS_CACHE_EXPRESSION:20,20:"JS_CACHE_EXPRESSION",JS_BLOCK_STATEMENT:21,21:"JS_BLOCK_STATEMENT",JS_TEMPLATE_LITERAL:22,22:"JS_TEMPLATE_LITERAL",JS_IF_STATEMENT:23,23:"JS_IF_STATEMENT",JS_ASSIGNMENT_EXPRESSION:24,24:"JS_ASSIGNMENT_EXPRESSION",JS_SEQUENCE_EXPRESSION:25,25:"JS_SEQUENCE_EXPRESSION",JS_RETURN_STATEMENT:26,26:"JS_RETURN_STATEMENT"},eE={ELEMENT:0,0:"ELEMENT",COMPONENT:1,1:"COMPONENT",SLOT:2,2:"SLOT",TEMPLATE:3,3:"TEMPLATE"},e_={NOT_CONSTANT:0,0:"NOT_CONSTANT",CAN_SKIP_PATCH:1,1:"CAN_SKIP_PATCH",CAN_CACHE:2,2:"CAN_CACHE",CAN_STRINGIFY:3,3:"CAN_STRINGIFY"},em={start:{line:1,column:1,offset:0},end:{line:1,column:1,offset:0},source:""};function eS(e,t=""){return{type:0,source:t,children:e,helpers:new Set,components:[],directives:[],hoists:[],imports:[],cached:[],temps:0,codegenNode:void 0,loc:em}}function eg(e,t,n,i,s,r,o,a=!1,l=!1,c=!1,h=em){return e&&(a?(e.helper(L),e.helper(eX(e.inSSR,c))):e.helper(ek(e.inSSR,c)),o&&e.helper(H)),{type:13,tag:t,props:n,children:i,patchFlag:s,dynamicProps:r,directives:o,isBlock:a,disableTracking:l,isComponent:c,loc:h}}function eT(e,t=em){return{type:17,loc:t,elements:e}}function eN(e,t=em){return{type:15,loc:t,properties:e}}funct
Line truncated
|
||||
Details: ${r}`:""}`);o.code=e,n&&(o.loc=n),t.onWarn(o)}function ez(e){throw e}function eZ(e){}function e1(e,t,n,i){let s=SyntaxError(String(`https://vuejs.org/error-reference/#compiler-${e}`));return s.code=e,s.loc=t,s}let e0={ABRUPT_CLOSING_OF_EMPTY_COMMENT:0,0:"ABRUPT_CLOSING_OF_EMPTY_COMMENT",CDATA_IN_HTML_CONTENT:1,1:"CDATA_IN_HTML_CONTENT",DUPLICATE_ATTRIBUTE:2,2:"DUPLICATE_ATTRIBUTE",END_TAG_WITH_ATTRIBUTES:3,3:"END_TAG_WITH_ATTRIBUTES",END_TAG_WITH_TRAILING_SOLIDUS:4,4:"END_TAG_WITH_TRAILING_SOLIDUS",EOF_BEFORE_TAG_NAME:5,5:"EOF_BEFORE_TAG_NAME",EOF_IN_CDATA:6,6:"EOF_IN_CDATA",EOF_IN_COMMENT:7,7:"EOF_IN_COMMENT",EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT:8,8:"EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT",EOF_IN_TAG:9,9:"EOF_IN_TAG",INCORRECTLY_CLOSED_COMMENT:10,10:"INCORRECTLY_CLOSED_COMMENT",INCORRECTLY_OPENED_COMMENT:11,11:"INCORRECTLY_OPENED_COMMENT",INVALID_FIRST_CHARACTER_OF_TAG_NAME:12,12:"INVALID_FIRST_CHARACTER_OF_TAG_NAME",MISSING_ATTRIBUTE_VALUE:13,13:"MISSING_ATTRIBUTE_VALUE",MISSING_END_TAG_NAME:14,14:"MISSING_END_TAG_NAME",MISSING_WHITESPACE_BETWEEN_ATTRIBUTES:15,15:"MISSING_WHITESPACE_BETWEEN_ATTRIBUTES",NESTED_COMMENT:16,16:"NESTED_COMMENT",UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME:17,17:"UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME",UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE:18,18:"UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE",UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME:19,19:"UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME",UNEXPECTED_NULL_CHARACTER:20,20:"UNEXPECTED_NULL_CHARACTER",UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME:21,21:"UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME",UNEXPECTED_SOLIDUS_IN_TAG:22,22:"UNEXPECTED_SOLIDUS_IN_TAG",X_INVALID_END_TAG:23,23:"X_INVALID_END_TAG",X_MISSING_END_TAG:24,24:"X_MISSING_END_TAG",X_MISSING_INTERPOLATION_END:25,25:"X_MISSING_INTERPOLATION_END",X_MISSING_DIRECTIVE_NAME:26,26:"X_MISSING_DIRECTIVE_NAME",X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END:27,27:"X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END",X_V_IF_NO_EXPRESSION:28,28:"X_V_IF_NO_EXPRESSION",X_V_IF_SAME_KEY:29,29:"X_V_IF_SAME_KEY",X_V_ELSE_NO_ADJACENT_IF:30,30:"X_V_ELSE_NO_ADJACENT_IF",X_V_FOR_NO_EXPRESSION:31,31:"X_V_FOR_NO_EXPRESSION",X_V_FOR_MALFORMED_EXPRESSION:32,32:"X_V_FOR_MALFORMED_EXPRESSION",X_V_FOR_TEMPLATE_KEY_PLACEMENT:33,33:"X_V_FOR_TEMPLATE_KEY_PLACEMENT",X_V_BIND_NO_EXPRESSION:34,34:"X_V_BIND_NO_EXPRESSION",X_V_ON_NO_EXPRESSION:35,35:"X_V_ON_NO_EXPRESSION",X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET:36,36:"X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET",X_V_SLOT_MIXED_SLOT_USAGE:37,37:"X_V_SLOT_MIXED_SLOT_USAGE",X_V_SLOT_DUPLICATE_SLOT_NAMES:38,38:"X_V_SLOT_DUPLICATE_SLOT_NAMES",X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN:39,39:"X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN",X_V_SLOT_MISPLACED:40,40:"X_V_SLOT_MISPLACED",X_V_MODEL_NO_EXPRESSION:41,41:"X_V_MODEL_NO_EXPRESSION",X_V_MODEL_MALFORMED_EXPRESSION:42,42:"X_V_MODEL_MALFORMED_EXPRESSION",X_V_MODEL_ON_SCOPE_VARIABLE:43,43:"X_V_MODEL_ON_SCOPE_VARIABLE",X_V_MODEL_ON_PROPS:44,44:"X_V_MODEL_ON_PROPS",X_V_MODEL_ON_CONST:45,45:"X_V_MODEL_ON_CONST",X_INVALID_EXPRESSION:46,46:"X_INVALID_EXPRESSION",X_KEEP_ALIVE_INVALID_CHILDREN:47,47:"X_KEEP_ALIVE_INVALID_CHILDREN",X_PREFIX_ID_NOT_SUPPORTED:48,48:"X_PREFIX_ID_NOT_SUPPORTED",X_MODULE_MODE_NOT_SUPPORTED:49,49:"X_MODULE_MODE_NOT_SUPPORTED",X_CACHE_HANDLER_NOT_SUPPORTED:50,50:"X_CACHE_HANDLER_NOT_SUPPORTED",X_SCOPE_ID_NOT_SUPPORTED:51,51:"X_SCOPE_ID_NOT_SUPPORTED",X_VNODE_HOOKS:52,52:"X_VNODE_HOOKS",X_V_BIND_INVALID_SAME_NAME_ARGUMENT:53,53:"X_V_BIND_INVALID_SAME_NAME_ARGUMENT",__EXTEND_POINT__:54,54:"__EXTEND_POINT__"},e2={0:"Illegal comment.",1:"CDATA section is allowed only in XML context.",2:"Duplicate attribute.",3:"End tag cannot have attributes.",4:"Illegal '/' in tags.",5:"Unexpected EOF in tag.",6:"Unexpected EOF in CDATA section.",7:"Unexpected EOF in comment.",8:"Unexpected EOF in script.",9:"Unexpected EOF in tag.",10:"Incorrectly closed comment.",11:"Incorrectly opened comment.",12:"Illegal tag name. Use '<' to print '<'.",13:"Attribute value was expected.",14:"End tag name was expected.",15:"Whitespace was expected.",16:"Unexpected '\x3c!--' in comment.",17:"Attribute name cannot contain U+0022 (\"), U+0027 ('), and U+003C (<).",18:"Unquoted attribute value cannot contain U+0022 (\"), U+0027 ('), U+003C (<), U+003D (=), and U+0060 (`).",19:"Attribute name cannot start with '='.",21:"'<?' is allowed only in XML context.",20:"Unexpected null character.",22:"Illegal '/' in tags.",23:"Invalid end tag.",24:"Element is missing end tag.",25:"Interpolation end sign was not found.",27:"End bracket for dynamic directive argument was not found. Note that dynamic directive argument cannot contain spaces.",26:"Legal directive name was expected.",28:"v-if/v-else-if is missing expression.",29:"v-if/else branches must use unique keys.",30:"v-else/v-else-if has no adjacent v-if or v-else-if.",31:"v-for is missing expression.",32:"v-for has invalid expression.",33:"<template v-for> key should be placed onLine truncated
|
||||
Use a v-bind binding combined with a v-on listener that emits update:x event instead.`,45:"v-model cannot be used on a const binding because it is not writable.",46:"Error parsing JavaScript expression: ",47:"<KeepAlive> expects exactly one child component.",52:"@vnode-* hooks in templates are no longer supported. Use the vue: prefix instead. For example, @vnode-mounted should be changed to @vue:mounted. @vnode-* hooks support has been removed in 3.4.",48:'"prefixIdentifiers" option is not supported in this build of compiler.',49:"ES module mode is not supported in this build of compiler.",50:'"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.',51:'"scopeId" option is only supported in module mode.',54:""};function e3(e,t,n=!1,i=[],s=Object.create(null)){}function e4(e,t,n){return!1}function e6(e,t){if(e&&("ObjectProperty"===e.type||"ArrayPattern"===e.type)){let e=t.length;for(;e--;){let n=t[e];if("AssignmentExpression"===n.type)return!0;if("ObjectProperty"!==n.type&&!n.type.endsWith("Pattern"))break}}return!1}function e5(e){let t=e.length;for(;t--;){let n=e[t];if("NewExpression"===n.type)return!0;if("MemberExpression"!==n.type)break}return!1}function e9(e,t){for(let n of e.params)for(let e of e8(n))t(e)}function e7(e,t){for(let i of"SwitchCase"===e.type?e.consequent:e.body)if("VariableDeclaration"===i.type){if(i.declare)continue;for(let e of i.declarations)for(let n of e8(e.id))t(n)}else if("FunctionDeclaration"===i.type||"ClassDeclaration"===i.type){if(i.declare||!i.id)continue;t(i.id)}else{var n;"ForOfStatement"===(n=i).type||"ForInStatement"===n.type||"ForStatement"===n.type?function(e,t,n){let i="ForStatement"===e.type?e.init:e.left;if(i&&"VariableDeclaration"===i.type&&("var"===i.kind?t:!t))for(let e of i.declarations)for(let t of e8(e.id))n(t)}(i,!0,t):"SwitchStatement"===i.type&&function(e,t,n){for(let i of e.cases){for(let e of i.consequent)if("VariableDeclaration"===e.type&&("var"===e.kind?t:!t))for(let t of e.declarations)for(let e of e8(t.id))n(e);e7(i,n)}}(i,!0,t)}}function e8(e,t=[]){switch(e.type){case"Identifier":t.push(e);break;case"MemberExpression":let n=e;for(;"MemberExpression"===n.type;)n=n.object;t.push(n);break;case"ObjectPattern":for(let n of e.properties)"RestElement"===n.type?e8(n.argument,t):e8(n.value,t);break;case"ArrayPattern":e.elements.forEach(e=>{e&&e8(e,t)});break;case"RestElement":e8(e.argument,t);break;case"AssignmentPattern":e8(e.left,t)}return t}let te=e=>/Function(?:Expression|Declaration)$|Method$/.test(e.type),tt=e=>e&&("ObjectProperty"===e.type||"ObjectMethod"===e.type)&&!e.computed,tn=(e,t)=>tt(t)&&t.key===e,ti=["TSAsExpression","TSTypeAssertion","TSNonNullExpression","TSInstantiationExpression","TSSatisfiesExpression"];function ts(e){return ti.includes(e.type)?ts(e.expression):e}let tr=e=>4===e.type&&e.isStatic;function to(e){switch(e){case"Teleport":case"teleport":return b;case"Suspense":case"suspense":return v;case"KeepAlive":case"keep-alive":return R;case"BaseTransition":case"base-transition":return x}}let ta=/^$|^\d|[^\$\w\xA0-\uFFFF]/,tl=e=>!ta.test(e),tc=/[A-Za-z_$\xA0-\uFFFF]/,th=/[\.\?\w$\xA0-\uFFFF]/,td=/\s+[.[]\s*|\s*[.[]\s+/g,tp=e=>4===e.type?e.content:e.loc.source,tu=e=>{let t=tp(e).trim().replace(td,e=>e.trim()),n=0,i=[],s=0,r=0,o=null;for(let e=0;e<t.length;e++){let a=t.charAt(e);switch(n){case 0:if("["===a)i.push(n),n=1,s++;else if("("===a)i.push(n),n=2,r++;else if(!(0===e?tc:th).test(a))return!1;break;case 1:"'"===a||'"'===a||"`"===a?(i.push(n),n=3,o=a):"["===a?s++:"]"!==a||--s||(n=i.pop());break;case 2:if("'"===a||'"'===a||"`"===a)i.push(n),n=3,o=a;else if("("===a)r++;else if(")"===a){if(e===t.length-1)return!1;--r||(n=i.pop())}break;case 3:a===o&&(n=i.pop(),o=null)}}return!s&&!r},tf=i,tE=tu,t_=/^\s*(?:async\s*)?(?:\([^)]*?\)|[\w$_]+)\s*(?::[^=]+)?=>|^\s*(?:async\s+)?function(?:\s+[\w$]+)?\s*\(/,tm=e=>t_.test(tp(e)),tS=i,tg=tm;function tT(e,t,n=t.length){return tN({offset:e.offset,line:e.line,column:e.column},t,n)}function tN(e,t,n=t.length){let i=0,s=-1;for(let e=0;e<n;e++)10===t.charCodeAt(e)&&(i++,s=e);return e.offset+=n,e.line+=i,e.column=-1===s?e.column+n:n-s,e}function tI(e,t){if(!e)throw Error(t||"unexpected compiler condition")}function ty(e,t,n=!1){for(let i=0;i<e.props.length;i++){let s=e.props[i];if(7===s.type&&(n||s.exp)&&(l(t)?s.name===t:t.test(s.name)))return s}}function tO(e,t,n=!1,i=!1){for(let s=0;s<e.props.length;s++){let r=e.props[s];if(6===r.type){if(n)continue;if(r.name===t&&(r.value||i))return r}else if("bind"===r.name&&(r.exp||i)&&tA(r.arg,t))return r}}function tA(e,t){return!!(e&&tr(e)&&e.content===t)}function tC(e){return e.props.some(e=>7===e.type&&"bind"===e.name&&(!e.arg||4!==e.arg.type||!e.arg.isStatic))}function tb(e){return 5===e.type||2===e.type}function tv(e){return 7===e.type&&"pre"===e.name}function tR(e){return 7===e.type&&"slot"===e.name}function tx(e){return 1===e.type&&3===e.tagType}function tL(e){return 1===e.type&&2===e.tagType}let tM=new Set([Q,z]);function tD(e,t,n)
Line truncated
|
||||
`);else if(tU(s.content)){let r=e[i-1]&&e[i-1].type,o=e[i+1]&&e[i+1].type;!r||!o||t&&(3===r&&(3===o||1===o)||1===r&&(3===o||1===o&&function(e){for(let t=0;t<e.length;t++){let n=e.charCodeAt(t);if(10===n||13===n)return!0}return!1}(s.content)))?(n=!0,e[i]=null):s.content=" "}else t&&(s.content=ni(s.content))}return n?e.filter(Boolean):e}function ni(e){let t="",n=!1;for(let i=0;i<e.length;i++)e$(e.charCodeAt(i))?n||(t+=" ",n=!0):(t+=e[i],n=!1);return t}function ns(e){(t1[0]||tG).children.push(e)}function nr(e,t){return{start:t0.getPos(e),end:null==t?t:t0.getPos(t),source:null==t?t:t4(e,t)}}function no(e,t){e.end=t0.getPos(t),e.source=t4(e.start.offset,t)}function na(e,t=!1,n,i=0,s=0){return ey(e,t,n,i)}function nl(e,t,n){tH.onError(e1(e,nr(t,t)))}function nc(e,t){if(t0.reset(),tJ=null,tj=null,tW="",tK=-1,tY=-1,t1.length=0,tq=e,tH=o({},t$),t){let e;for(e in t)null!=t[e]&&(tH[e]=t[e])}t0.mode="html"===tH.parseMode?1:2*("sfc"===tH.parseMode),t0.inXML=1===tH.ns||2===tH.ns;let n=t&&t.delimiters;n&&(t0.delimiterOpen=eG(n[0]),t0.delimiterClose=eG(n[1]));let i=tG=eS([],e);return t0.parse(tq),i.loc=nr(0,e.length),i.children=nn(i.children),tG=null,i}function nh(e){let t=e.children.filter(e=>3!==e.type);return 1!==t.length||1!==t[0].type||tL(t[0])?null:t[0]}function nd(e,t){let{constantCache:n}=t;switch(e.type){case 1:if(0!==e.tagType)return 0;let i=n.get(e);if(void 0!==i)return i;let s=e.codegenNode;if(13!==s.type||s.isBlock&&"svg"!==e.tag&&"foreignObject"!==e.tag&&"math"!==e.tag)return 0;if(void 0!==s.patchFlag)return n.set(e,0),0;{let i=3,r=nu(e,t);if(0===r)return n.set(e,0),0;r<i&&(i=r);for(let s=0;s<e.children.length;s++){let r=nd(e.children[s],t);if(0===r)return n.set(e,0),0;r<i&&(i=r)}if(i>1)for(let s=0;s<e.props.length;s++){let r=e.props[s];if(7===r.type&&"bind"===r.name&&r.exp){let s=nd(r.exp,t);if(0===s)return n.set(e,0),0;s<i&&(i=s)}}if(s.isBlock){for(let t=0;t<e.props.length;t++)if(7===e.props[t].type)return n.set(e,0),0;t.removeHelper(L),t.removeHelper(eX(t.inSSR,s.isComponent)),s.isBlock=!1,t.helper(ek(t.inSSR,s.isComponent))}return n.set(e,i),i}case 2:case 3:return 3;case 9:case 11:case 10:default:return 0;case 5:case 12:return nd(e.content,t);case 4:return e.constType;case 8:let r=3;for(let n=0;n<e.children.length;n++){let i=e.children[n];if(l(i)||c(i))continue;let s=nd(i,t);if(0===s)return 0;s<r&&(r=s)}return r;case 20:return 2}}let np=new Set([K,Y,Q,z]);function nu(e,t){let n=3,i=nf(e);if(i&&15===i.type){let{properties:e}=i;for(let i=0;i<e.length;i++){let s,{key:r,value:o}=e[i],a=nd(r,t);if(0===a)return a;if(a<n&&(n=a),0===(s=4===o.type?nd(o,t):14===o.type?function e(t,n){if(14===t.type&&!l(t.callee)&&np.has(t.callee)){let i=t.arguments[0];if(4===i.type)return nd(i,n);if(14===i.type)return e(i,n)}return 0}(o,t):0))return s;s<n&&(n=s)}}return n}function nf(e){let t=e.codegenNode;if(13===t.type)return t.props}function nE(e,{filename:t="",prefixIdentifiers:s=!1,hoistStatic:r=!1,hmr:o=!1,cacheHandlers:a=!1,nodeTransforms:c=[],directiveTransforms:h={},transformHoist:d=null,isBuiltInComponent:p=i,isCustomElement:u=i,expressionPlugins:f=[],scopeId:m=null,slotted:S=!0,ssr:g=!1,inSSR:T=!1,ssrCssVars:N="",bindingMetadata:I=n,inline:y=!1,isTS:O=!1,onError:A=ez,onWarn:C=eZ,compatConfig:b}){let v=t.replace(/\?.*$/,"").match(/([^/\\]+)\.\w+$/),R={filename:t,selfName:v&&_(E(v[1])),prefixIdentifiers:s,hoistStatic:r,hmr:o,cacheHandlers:a,nodeTransforms:c,directiveTransforms:h,transformHoist:d,isBuiltInComponent:p,isCustomElement:u,expressionPlugins:f,scopeId:m,slotted:S,ssr:g,inSSR:T,ssrCssVars:N,bindingMetadata:I,inline:y,isTS:O,onError:A,onWarn:C,compatConfig:b,root:e,helpers:new Map,components:new Set,directives:new Set,hoists:[],imports:[],cached:[],constantCache:new WeakMap,temps:0,identifiers:Object.create(null),scopes:{vFor:0,vSlot:0,vPre:0,vOnce:0},parent:null,grandParent:null,currentNode:e,childIndex:0,inVOnce:!1,helper(e){let t=R.helpers.get(e)||0;return R.helpers.set(e,t+1),e},removeHelper(e){let t=R.helpers.get(e);if(t){let n=t-1;n?R.helpers.set(e,n):R.helpers.delete(e)}},helperString:e=>`_${ed[R.helper(e)]}`,replaceNode(e){R.parent.children[R.childIndex]=R.currentNode=e},removeNode(e){let t=R.parent.children,n=e?t.indexOf(e):R.currentNode?R.childIndex:-1;e&&e!==R.currentNode?R.childIndex>n&&(R.childIndex--,R.onNodeRemoved()):(R.currentNode=null,R.onNodeRemoved()),R.parent.children.splice(n,1)},onNodeRemoved:i,addIdentifiers(e){},removeIdentifiers(e){},hoist(e){l(e)&&(e=ey(e)),R.hoists.push(e);let t=ey(`_hoisted_${R.hoists.length}`,!1,e.loc,2);return t.hoisted=e,t},cache(e,t=!1,n=!1){let i=eR(R.cached.length,e,t,n);return R.cached.push(i),i}};return R.filters=new Set,R}function n_(e,t){let n=nE(e,t);nm(e,n),t.hoistStatic&&function e(t,n,i,s=!1,r=!1){let{children:o}=t,l=[];for(let n=0;n<o.length;n++){let a=o[n];if(1===a.type&&0===a.tagType){let e=s?0:nd(a,i);if(e>0){if(e>=2){a.codegenNode.patchFlag=-1,l.push(a);continue}}else{let e=a.codegenNode;if(13===e.type){let t=e.patchFlag;if((void 0===t||512===t||1===
Line truncated
|
||||
`+" ".repeat(e),0)}return u}(e,t);t.onContextCreated&&t.onContextCreated(n);let{mode:i,push:s,prefixIdentifiers:r,indent:o,deindent:a,newline:l,ssr:c}=n,h=Array.from(e.helpers),d=h.length>0,p=!r&&"module"!==i;!function(e,t){let{push:n,newline:i,runtimeGlobalName:s}=t,r=Array.from(e.helpers);if(r.length>0&&(n(`const _Vue = ${s}
|
||||
`,-1),e.hoists.length)){let e=[P,V,k,X,w].filter(e=>r.includes(e)).map(nT).join(", ");n(`const { ${e} } = _Vue
|
||||
`,-1)}(function(e,t){if(!e.length)return;t.pure=!0;let{push:n,newline:i}=t;i();for(let s=0;s<e.length;s++){let r=e[s];r&&(n(`const _hoisted_${s+1} = `),nA(r,t),i())}t.pure=!1})(e.hoists,t),i(),n("return ")}(e,n);let u=(c?["_ctx","_push","_parent","_attrs"]:["_ctx","_cache"]).join(", ");if(s(`function ${c?"ssrRender":"render"}(${u}) {`),o(),p&&(s("with (_ctx) {"),o(),d&&(s(`const { ${h.map(nT).join(", ")} } = _Vue
|
||||
`,-1),l())),e.components.length&&(nI(e.components,"component",n),(e.directives.length||e.temps>0)&&l()),e.directives.length&&(nI(e.directives,"directive",n),e.temps>0&&l()),e.filters&&e.filters.length&&(l(),nI(e.filters,"filter",n),l()),e.temps>0){s("let ");for(let t=0;t<e.temps;t++)s(`${t>0?", ":""}_temp${t}`)}return(e.components.length||e.directives.length||e.temps)&&(s(`
|
||||
`,0),l()),c||s("return "),e.codegenNode?nA(e.codegenNode,n):s("null"),p&&(a(),s("}")),a(),s("}"),{ast:e,code:n.code,preamble:"",map:n.map?n.map.toJSON():void 0}}function nI(e,t,{helper:n,push:i,newline:s,isTS:r}){let o=n("filter"===t?$:"component"===t?U:B);for(let n=0;n<e.length;n++){let a=e[n],l=a.endsWith("__self");l&&(a=a.slice(0,-6)),i(`const ${tV(a,t)} = ${o}(${JSON.stringify(a)}${l?", true":""})${r?"!":""}`),n<e.length-1&&s()}}function ny(e,t){let n=e.length>3;t.push("["),n&&t.indent(),nO(e,t,n),n&&t.deindent(),t.push("]")}function nO(e,t,n=!1,i=!0){let{push:s,newline:r}=t;for(let o=0;o<e.length;o++){let c=e[o];l(c)?s(c,-3):a(c)?ny(c,t):nA(c,t),o<e.length-1&&(n?(i&&s(","),r()):i&&s(", "))}}function nA(e,t){var n,i,s;if(l(e))return void t.push(e,-3);if(c(e))return void t.push(t.helper(e));switch(e.type){case 1:case 9:case 11:case 12:nA(e.codegenNode,t);break;case 2:n=e,t.push(JSON.stringify(n.content),-3,n);break;case 4:nC(e,t);break;case 5:!function(e,t){let{push:n,helper:i,pure:s}=t;s&&n(ng),n(`${i(j)}(`),nA(e.content,t),n(")")}(e,t);break;case 8:nb(e,t);break;case 3:!function(e,t){let{push:n,helper:i,pure:s}=t;s&&n(ng),n(`${i(k)}(${JSON.stringify(e.content)})`,-3,e)}(e,t);break;case 13:!function(e,t){let n,{push:i,helper:s,pure:r}=t,{tag:o,props:a,children:l,patchFlag:c,dynamicProps:h,directives:d,isBlock:p,disableTracking:u,isComponent:f}=e;c&&(n=String(c)),d&&i(s(H)+"("),p&&i(`(${s(L)}(${u?"true":""}), `),r&&i(ng),i(s(p?eX(t.inSSR,f):ek(t.inSSR,f))+"(",-2,e),nO(function(e){let t=e.length;for(;t--&&null==e[t];);return e.slice(0,t+1).map(e=>e||"null")}([o,a,l,n,h]),t),i(")"),p&&i(")"),d&&(i(", "),nA(d,t),i(")"))}(e,t);break;case 14:!function(e,t){let{push:n,helper:i,pure:s}=t,r=l(e.callee)?e.callee:i(e.callee);s&&n(ng),n(r+"(",-2,e),nO(e.arguments,t),n(")")}(e,t);break;case 15:!function(e,t){let{push:n,indent:i,deindent:s,newline:r}=t,{properties:o}=e;if(!o.length)return n("{}",-2,e);let a=o.length>1;n(a?"{":"{ "),a&&i();for(let e=0;e<o.length;e++){let{key:i,value:s}=o[e];!function(e,t){let{push:n}=t;8===e.type?(n("["),nb(e,t),n("]")):e.isStatic?n(tl(e.content)?e.content:JSON.stringify(e.content),-2,e):n(`[${e.content}]`,-3,e)}(i,t),n(": "),nA(s,t),e<o.length-1&&(n(","),r())}a&&s(),n(a?"}":" }")}(e,t);break;case 17:i=e,s=t,ny(i.elements,s);break;case 18:!function(e,t){let{push:n,indent:i,deindent:s}=t,{params:r,returns:o,body:l,newline:c,isSlot:h}=e;h&&n(`_${ed[eo]}(`),n("(",-2,e),a(r)?nO(r,t):r&&nA(r,t),n(") => "),(c||l)&&(n("{"),i()),o?(c&&n("return "),a(o)?ny(o,t):nA(o,t)):l&&nA(l,t),(c||l)&&(s(),n("}")),h&&(e.isNonScopedSlot&&n(", undefined, true"),n(")"))}(e,t);break;case 19:!function(e,t){let{test:n,consequent:i,alternate:s,newline:r}=e,{push:o,indent:a,deindent:l,newline:c}=t;if(4===n.type){let e=!tl(n.content);e&&o("("),nC(n,t),e&&o(")")}else o("("),nA(n,t),o(")");r&&a(),t.indentLevel++,r||o(" "),o("? "),nA(i,t),t.indentLevel--,r&&c(),r||o(" "),o(": ");let h=19===s.type;!h&&t.indentLevel++,nA(s,t),!h&&t.indentLevel--,r&&l(!0)}(e,t);break;case 20:!function(e,t){let{push:n,helper:i,indent:s,deindent:r,newline:o}=t,{needPauseTracking:a,needArraySpread:l}=e;l&&n("[...("),n(`_cache[${e.index}] || (`),a&&(s(),n(`${i(ei)}(-1`),e.inVOnce&&n(", true"),n("),"),o(),n("(")),n(`_cache[${e.index}] = `),nA(e.value,t),a&&(n(`).cacheIndex = ${e.index},`),o(),n(`${i(ei)}(1),`),o(),n(`_cache[${e.index}]`),r()),n(")"),l&&n(")]")}(e,t);break;case 21:nO(e.body,t,!0,!1)}}function nC(e,t){let{content:n,isStatic:i}=e;t.push(i?JSON.stringify(n):n,-3,e)}function nb(e,t){for(let n=0;n<e.children.length;n++){let i=e.children[n];l(i)?t.push(i,-3):nA(i,t)}}let nv=(e,t)=>{if(5===e.type)e.content=nR(e.content,t);else if(1===e.type){let n=ty(e,"memo");for(let i=0;i<e.props.length;i++){let s=e.props[i];if(7===s.type&&"for"!==s.name){let e=s.exp,i=s.arg;!e||4!==e.type||"on"===s.name&&i||n&&i&&4===i.type&&"key"===i.content||(s.exp=nR(e,t,"slot"===s.name)),i&&4===i.type&&!i.isStatic&&(s.arg=nR(i,t))}}}};function nR(e,t,n=!1,i=!1,s=Object.create(t.identifiers)){return e}function nx(e){return l(e)?e:4===e.type?e.content:e.children.map(nx).join("")}let nL=nS(/^(?:if|else|else-if)$/,(e,t,n)=>nM(e,t,n,(e,t,i)=>{let s=n.parent.children,r=s.indexOf(e),o=0;for(;r-- >=0;){let e=s[r];e&&9===e.type&&(o+=e.branches.length)}return()=>{i?e.codegenNode=nP(t,o,n):function(e){for(;;)if(19===e.type)if(19!==e.alternate.type)return e;else e=e.alternate;else 20===e.type&&(e=e.value)}(e.codegenNode).alternate=nP(t,o+e.branches.length-1,n)}}));function nM(e,t,n,i){if("else"!==t.name&&(!t.exp||!t.exp.content.trim())){let i=t.exp?t.exp.loc:e.loc;n.onError(e1(28,t.loc)),t.exp=ey("true",!1,i)}if("if"===t.name){var s;let r=nD(e,t),o={type:9,loc:nr((s=e.loc).start.offset,s.end.offset),branches:[r]};if(n.replaceNode(o),i)return i(o,r,!0)}else{let s=n.parent.children,r=s.indexOf(e);for(;r-- >=-1;){let o=s[r];if(o&&tB(o)){n.removeNode(o);continue}if(o&&9===o.type){("else-if"===t.name||"else"===t.name)&&void 0===o.branches[o.branches.length-1].condition&&n.onE
Line truncated
|
||||
+690
@@ -0,0 +1,690 @@
|
||||
/**
|
||||
* @vue/compiler-dom v3.5.30
|
||||
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
||||
* @license MIT
|
||||
**/
|
||||
import { registerRuntimeHelpers, createSimpleExpression, createCompilerError, createObjectProperty, getConstantType, createCallExpression, TO_DISPLAY_STRING, transformModel as transformModel$1, findProp, hasDynamicKeyVBind, findDir, isStaticArgOf, transformOn as transformOn$1, isStaticExp, createCompoundExpression, checkCompatEnabled, isCommentOrWhitespace, noopDirectiveTransform, baseCompile, baseParse } from '@vue/compiler-core';
|
||||
export * from '@vue/compiler-core';
|
||||
import { isVoidTag, isHTMLTag, isSVGTag, isMathMLTag, parseStringStyle, capitalize, makeMap, extend } from '@vue/shared';
|
||||
|
||||
const V_MODEL_RADIO = /* @__PURE__ */ Symbol(!!(process.env.NODE_ENV !== "production") ? `vModelRadio` : ``);
|
||||
const V_MODEL_CHECKBOX = /* @__PURE__ */ Symbol(
|
||||
!!(process.env.NODE_ENV !== "production") ? `vModelCheckbox` : ``
|
||||
);
|
||||
const V_MODEL_TEXT = /* @__PURE__ */ Symbol(!!(process.env.NODE_ENV !== "production") ? `vModelText` : ``);
|
||||
const V_MODEL_SELECT = /* @__PURE__ */ Symbol(
|
||||
!!(process.env.NODE_ENV !== "production") ? `vModelSelect` : ``
|
||||
);
|
||||
const V_MODEL_DYNAMIC = /* @__PURE__ */ Symbol(
|
||||
!!(process.env.NODE_ENV !== "production") ? `vModelDynamic` : ``
|
||||
);
|
||||
const V_ON_WITH_MODIFIERS = /* @__PURE__ */ Symbol(
|
||||
!!(process.env.NODE_ENV !== "production") ? `vOnModifiersGuard` : ``
|
||||
);
|
||||
const V_ON_WITH_KEYS = /* @__PURE__ */ Symbol(
|
||||
!!(process.env.NODE_ENV !== "production") ? `vOnKeysGuard` : ``
|
||||
);
|
||||
const V_SHOW = /* @__PURE__ */ Symbol(!!(process.env.NODE_ENV !== "production") ? `vShow` : ``);
|
||||
const TRANSITION = /* @__PURE__ */ Symbol(!!(process.env.NODE_ENV !== "production") ? `Transition` : ``);
|
||||
const TRANSITION_GROUP = /* @__PURE__ */ Symbol(
|
||||
!!(process.env.NODE_ENV !== "production") ? `TransitionGroup` : ``
|
||||
);
|
||||
registerRuntimeHelpers({
|
||||
[V_MODEL_RADIO]: `vModelRadio`,
|
||||
[V_MODEL_CHECKBOX]: `vModelCheckbox`,
|
||||
[V_MODEL_TEXT]: `vModelText`,
|
||||
[V_MODEL_SELECT]: `vModelSelect`,
|
||||
[V_MODEL_DYNAMIC]: `vModelDynamic`,
|
||||
[V_ON_WITH_MODIFIERS]: `withModifiers`,
|
||||
[V_ON_WITH_KEYS]: `withKeys`,
|
||||
[V_SHOW]: `vShow`,
|
||||
[TRANSITION]: `Transition`,
|
||||
[TRANSITION_GROUP]: `TransitionGroup`
|
||||
});
|
||||
|
||||
let decoder;
|
||||
function decodeHtmlBrowser(raw, asAttr = false) {
|
||||
if (!decoder) {
|
||||
decoder = document.createElement("div");
|
||||
}
|
||||
if (asAttr) {
|
||||
decoder.innerHTML = `<div foo="${raw.replace(/"/g, """)}">`;
|
||||
return decoder.children[0].getAttribute("foo");
|
||||
} else {
|
||||
decoder.innerHTML = raw;
|
||||
return decoder.textContent;
|
||||
}
|
||||
}
|
||||
|
||||
const parserOptions = {
|
||||
parseMode: "html",
|
||||
isVoidTag,
|
||||
isNativeTag: (tag) => isHTMLTag(tag) || isSVGTag(tag) || isMathMLTag(tag),
|
||||
isPreTag: (tag) => tag === "pre",
|
||||
isIgnoreNewlineTag: (tag) => tag === "pre" || tag === "textarea",
|
||||
decodeEntities: decodeHtmlBrowser ,
|
||||
isBuiltInComponent: (tag) => {
|
||||
if (tag === "Transition" || tag === "transition") {
|
||||
return TRANSITION;
|
||||
} else if (tag === "TransitionGroup" || tag === "transition-group") {
|
||||
return TRANSITION_GROUP;
|
||||
}
|
||||
},
|
||||
// https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
|
||||
getNamespace(tag, parent, rootNamespace) {
|
||||
let ns = parent ? parent.ns : rootNamespace;
|
||||
if (parent && ns === 2) {
|
||||
if (parent.tag === "annotation-xml") {
|
||||
if (tag === "svg") {
|
||||
return 1;
|
||||
}
|
||||
if (parent.props.some(
|
||||
(a) => a.type === 6 && a.name === "encoding" && a.value != null && (a.value.content === "text/html" || a.value.content === "application/xhtml+xml")
|
||||
)) {
|
||||
ns = 0;
|
||||
}
|
||||
} else if (/^m(?:[ions]|text)$/.test(parent.tag) && tag !== "mglyph" && tag !== "malignmark") {
|
||||
ns = 0;
|
||||
}
|
||||
} else if (parent && ns === 1) {
|
||||
if (parent.tag === "foreignObject" || parent.tag === "desc" || parent.tag === "title") {
|
||||
ns = 0;
|
||||
}
|
||||
}
|
||||
if (ns === 0) {
|
||||
if (tag === "svg") {
|
||||
return 1;
|
||||
}
|
||||
if (tag === "math") {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
return ns;
|
||||
}
|
||||
};
|
||||
|
||||
const transformStyle = (node) => {
|
||||
if (node.type === 1) {
|
||||
node.props.forEach((p, i) => {
|
||||
if (p.type === 6 && p.name === "style" && p.value) {
|
||||
node.props[i] = {
|
||||
type: 7,
|
||||
name: `bind`,
|
||||
arg: createSimpleExpression(`style`, true, p.loc),
|
||||
exp: parseInlineCSS(p.value.content, p.loc),
|
||||
modifiers: [],
|
||||
loc: p.loc
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
const parseInlineCSS = (cssText, loc) => {
|
||||
const normalized = parseStringStyle(cssText);
|
||||
return createSimpleExpression(
|
||||
JSON.stringify(normalized),
|
||||
false,
|
||||
loc,
|
||||
3
|
||||
);
|
||||
};
|
||||
|
||||
function createDOMCompilerError(code, loc) {
|
||||
return createCompilerError(
|
||||
code,
|
||||
loc,
|
||||
!!(process.env.NODE_ENV !== "production") || false ? DOMErrorMessages : void 0
|
||||
);
|
||||
}
|
||||
const DOMErrorCodes = {
|
||||
"X_V_HTML_NO_EXPRESSION": 54,
|
||||
"54": "X_V_HTML_NO_EXPRESSION",
|
||||
"X_V_HTML_WITH_CHILDREN": 55,
|
||||
"55": "X_V_HTML_WITH_CHILDREN",
|
||||
"X_V_TEXT_NO_EXPRESSION": 56,
|
||||
"56": "X_V_TEXT_NO_EXPRESSION",
|
||||
"X_V_TEXT_WITH_CHILDREN": 57,
|
||||
"57": "X_V_TEXT_WITH_CHILDREN",
|
||||
"X_V_MODEL_ON_INVALID_ELEMENT": 58,
|
||||
"58": "X_V_MODEL_ON_INVALID_ELEMENT",
|
||||
"X_V_MODEL_ARG_ON_ELEMENT": 59,
|
||||
"59": "X_V_MODEL_ARG_ON_ELEMENT",
|
||||
"X_V_MODEL_ON_FILE_INPUT_ELEMENT": 60,
|
||||
"60": "X_V_MODEL_ON_FILE_INPUT_ELEMENT",
|
||||
"X_V_MODEL_UNNECESSARY_VALUE": 61,
|
||||
"61": "X_V_MODEL_UNNECESSARY_VALUE",
|
||||
"X_V_SHOW_NO_EXPRESSION": 62,
|
||||
"62": "X_V_SHOW_NO_EXPRESSION",
|
||||
"X_TRANSITION_INVALID_CHILDREN": 63,
|
||||
"63": "X_TRANSITION_INVALID_CHILDREN",
|
||||
"X_IGNORED_SIDE_EFFECT_TAG": 64,
|
||||
"64": "X_IGNORED_SIDE_EFFECT_TAG",
|
||||
"__EXTEND_POINT__": 65,
|
||||
"65": "__EXTEND_POINT__"
|
||||
};
|
||||
const DOMErrorMessages = {
|
||||
[54]: `v-html is missing expression.`,
|
||||
[55]: `v-html will override element children.`,
|
||||
[56]: `v-text is missing expression.`,
|
||||
[57]: `v-text will override element children.`,
|
||||
[58]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
|
||||
[59]: `v-model argument is not supported on plain elements.`,
|
||||
[60]: `v-model cannot be used on file inputs since they are read-only. Use a v-on:change listener instead.`,
|
||||
[61]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
|
||||
[62]: `v-show is missing expression.`,
|
||||
[63]: `<Transition> expects exactly one child element or component.`,
|
||||
[64]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
|
||||
};
|
||||
|
||||
const transformVHtml = (dir, node, context) => {
|
||||
const { exp, loc } = dir;
|
||||
if (!exp) {
|
||||
context.onError(
|
||||
createDOMCompilerError(54, loc)
|
||||
);
|
||||
}
|
||||
if (node.children.length) {
|
||||
context.onError(
|
||||
createDOMCompilerError(55, loc)
|
||||
);
|
||||
node.children.length = 0;
|
||||
}
|
||||
return {
|
||||
props: [
|
||||
createObjectProperty(
|
||||
createSimpleExpression(`innerHTML`, true, loc),
|
||||
exp || createSimpleExpression("", true)
|
||||
)
|
||||
]
|
||||
};
|
||||
};
|
||||
|
||||
const transformVText = (dir, node, context) => {
|
||||
const { exp, loc } = dir;
|
||||
if (!exp) {
|
||||
context.onError(
|
||||
createDOMCompilerError(56, loc)
|
||||
);
|
||||
}
|
||||
if (node.children.length) {
|
||||
context.onError(
|
||||
createDOMCompilerError(57, loc)
|
||||
);
|
||||
node.children.length = 0;
|
||||
}
|
||||
return {
|
||||
props: [
|
||||
createObjectProperty(
|
||||
createSimpleExpression(`textContent`, true),
|
||||
exp ? getConstantType(exp, context) > 0 ? exp : createCallExpression(
|
||||
context.helperString(TO_DISPLAY_STRING),
|
||||
[exp],
|
||||
loc
|
||||
) : createSimpleExpression("", true)
|
||||
)
|
||||
]
|
||||
};
|
||||
};
|
||||
|
||||
const transformModel = (dir, node, context) => {
|
||||
const baseResult = transformModel$1(dir, node, context);
|
||||
if (!baseResult.props.length || node.tagType === 1) {
|
||||
return baseResult;
|
||||
}
|
||||
if (dir.arg) {
|
||||
context.onError(
|
||||
createDOMCompilerError(
|
||||
59,
|
||||
dir.arg.loc
|
||||
)
|
||||
);
|
||||
}
|
||||
function checkDuplicatedValue() {
|
||||
const value = findDir(node, "bind");
|
||||
if (value && isStaticArgOf(value.arg, "value")) {
|
||||
context.onError(
|
||||
createDOMCompilerError(
|
||||
61,
|
||||
value.loc
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
const { tag } = node;
|
||||
const isCustomElement = context.isCustomElement(tag);
|
||||
if (tag === "input" || tag === "textarea" || tag === "select" || isCustomElement) {
|
||||
let directiveToUse = V_MODEL_TEXT;
|
||||
let isInvalidType = false;
|
||||
if (tag === "input" || isCustomElement) {
|
||||
const type = findProp(node, `type`);
|
||||
if (type) {
|
||||
if (type.type === 7) {
|
||||
directiveToUse = V_MODEL_DYNAMIC;
|
||||
} else if (type.value) {
|
||||
switch (type.value.content) {
|
||||
case "radio":
|
||||
directiveToUse = V_MODEL_RADIO;
|
||||
break;
|
||||
case "checkbox":
|
||||
directiveToUse = V_MODEL_CHECKBOX;
|
||||
break;
|
||||
case "file":
|
||||
isInvalidType = true;
|
||||
context.onError(
|
||||
createDOMCompilerError(
|
||||
60,
|
||||
dir.loc
|
||||
)
|
||||
);
|
||||
break;
|
||||
default:
|
||||
!!(process.env.NODE_ENV !== "production") && checkDuplicatedValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (hasDynamicKeyVBind(node)) {
|
||||
directiveToUse = V_MODEL_DYNAMIC;
|
||||
} else {
|
||||
!!(process.env.NODE_ENV !== "production") && checkDuplicatedValue();
|
||||
}
|
||||
} else if (tag === "select") {
|
||||
directiveToUse = V_MODEL_SELECT;
|
||||
} else {
|
||||
!!(process.env.NODE_ENV !== "production") && checkDuplicatedValue();
|
||||
}
|
||||
if (!isInvalidType) {
|
||||
baseResult.needRuntime = context.helper(directiveToUse);
|
||||
}
|
||||
} else {
|
||||
context.onError(
|
||||
createDOMCompilerError(
|
||||
58,
|
||||
dir.loc
|
||||
)
|
||||
);
|
||||
}
|
||||
baseResult.props = baseResult.props.filter(
|
||||
(p) => !(p.key.type === 4 && p.key.content === "modelValue")
|
||||
);
|
||||
return baseResult;
|
||||
};
|
||||
|
||||
const isEventOptionModifier = /* @__PURE__ */ makeMap(`passive,once,capture`);
|
||||
const isNonKeyModifier = /* @__PURE__ */ makeMap(
|
||||
// event propagation management
|
||||
`stop,prevent,self,ctrl,shift,alt,meta,exact,middle`
|
||||
);
|
||||
const maybeKeyModifier = /* @__PURE__ */ makeMap("left,right");
|
||||
const isKeyboardEvent = /* @__PURE__ */ makeMap(`onkeyup,onkeydown,onkeypress`);
|
||||
const resolveModifiers = (key, modifiers, context, loc) => {
|
||||
const keyModifiers = [];
|
||||
const nonKeyModifiers = [];
|
||||
const eventOptionModifiers = [];
|
||||
for (let i = 0; i < modifiers.length; i++) {
|
||||
const modifier = modifiers[i].content;
|
||||
if (modifier === "native" && checkCompatEnabled(
|
||||
"COMPILER_V_ON_NATIVE",
|
||||
context,
|
||||
loc
|
||||
)) {
|
||||
eventOptionModifiers.push(modifier);
|
||||
} else if (isEventOptionModifier(modifier)) {
|
||||
eventOptionModifiers.push(modifier);
|
||||
} else {
|
||||
if (maybeKeyModifier(modifier)) {
|
||||
if (isStaticExp(key)) {
|
||||
if (isKeyboardEvent(key.content.toLowerCase())) {
|
||||
keyModifiers.push(modifier);
|
||||
} else {
|
||||
nonKeyModifiers.push(modifier);
|
||||
}
|
||||
} else {
|
||||
keyModifiers.push(modifier);
|
||||
nonKeyModifiers.push(modifier);
|
||||
}
|
||||
} else {
|
||||
if (isNonKeyModifier(modifier)) {
|
||||
nonKeyModifiers.push(modifier);
|
||||
} else {
|
||||
keyModifiers.push(modifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
keyModifiers,
|
||||
nonKeyModifiers,
|
||||
eventOptionModifiers
|
||||
};
|
||||
};
|
||||
const transformClick = (key, event) => {
|
||||
const isStaticClick = isStaticExp(key) && key.content.toLowerCase() === "onclick";
|
||||
return isStaticClick ? createSimpleExpression(event, true) : key.type !== 4 ? createCompoundExpression([
|
||||
`(`,
|
||||
key,
|
||||
`) === "onClick" ? "${event}" : (`,
|
||||
key,
|
||||
`)`
|
||||
]) : key;
|
||||
};
|
||||
const transformOn = (dir, node, context) => {
|
||||
return transformOn$1(dir, node, context, (baseResult) => {
|
||||
const { modifiers } = dir;
|
||||
if (!modifiers.length) return baseResult;
|
||||
let { key, value: handlerExp } = baseResult.props[0];
|
||||
const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
|
||||
if (nonKeyModifiers.includes("right")) {
|
||||
key = transformClick(key, `onContextmenu`);
|
||||
}
|
||||
if (nonKeyModifiers.includes("middle")) {
|
||||
key = transformClick(key, `onMouseup`);
|
||||
}
|
||||
if (nonKeyModifiers.length) {
|
||||
handlerExp = createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
|
||||
handlerExp,
|
||||
JSON.stringify(nonKeyModifiers)
|
||||
]);
|
||||
}
|
||||
if (keyModifiers.length && // if event name is dynamic, always wrap with keys guard
|
||||
(!isStaticExp(key) || isKeyboardEvent(key.content.toLowerCase()))) {
|
||||
handlerExp = createCallExpression(context.helper(V_ON_WITH_KEYS), [
|
||||
handlerExp,
|
||||
JSON.stringify(keyModifiers)
|
||||
]);
|
||||
}
|
||||
if (eventOptionModifiers.length) {
|
||||
const modifierPostfix = eventOptionModifiers.map(capitalize).join("");
|
||||
key = isStaticExp(key) ? createSimpleExpression(`${key.content}${modifierPostfix}`, true) : createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
|
||||
}
|
||||
return {
|
||||
props: [createObjectProperty(key, handlerExp)]
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
const transformShow = (dir, node, context) => {
|
||||
const { exp, loc } = dir;
|
||||
if (!exp) {
|
||||
context.onError(
|
||||
createDOMCompilerError(62, loc)
|
||||
);
|
||||
}
|
||||
return {
|
||||
props: [],
|
||||
needRuntime: context.helper(V_SHOW)
|
||||
};
|
||||
};
|
||||
|
||||
const transformTransition = (node, context) => {
|
||||
if (node.type === 1 && node.tagType === 1) {
|
||||
const component = context.isBuiltInComponent(node.tag);
|
||||
if (component === TRANSITION) {
|
||||
return () => {
|
||||
if (!node.children.length) {
|
||||
return;
|
||||
}
|
||||
if (hasMultipleChildren(node)) {
|
||||
context.onError(
|
||||
createDOMCompilerError(
|
||||
63,
|
||||
{
|
||||
start: node.children[0].loc.start,
|
||||
end: node.children[node.children.length - 1].loc.end,
|
||||
source: ""
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
const child = node.children[0];
|
||||
if (child.type === 1) {
|
||||
for (const p of child.props) {
|
||||
if (p.type === 7 && p.name === "show") {
|
||||
node.props.push({
|
||||
type: 6,
|
||||
name: "persisted",
|
||||
nameLoc: node.loc,
|
||||
value: void 0,
|
||||
loc: node.loc
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
function hasMultipleChildren(node) {
|
||||
const children = node.children = node.children.filter(
|
||||
(c) => !isCommentOrWhitespace(c)
|
||||
);
|
||||
const child = children[0];
|
||||
return children.length !== 1 || child.type === 11 || child.type === 9 && child.branches.some(hasMultipleChildren);
|
||||
}
|
||||
|
||||
const ignoreSideEffectTags = (node, context) => {
|
||||
if (node.type === 1 && node.tagType === 0 && (node.tag === "script" || node.tag === "style")) {
|
||||
!!(process.env.NODE_ENV !== "production") && context.onError(
|
||||
createDOMCompilerError(
|
||||
64,
|
||||
node.loc
|
||||
)
|
||||
);
|
||||
context.removeNode();
|
||||
}
|
||||
};
|
||||
|
||||
function isValidHTMLNesting(parent, child) {
|
||||
if (parent === "template") {
|
||||
return true;
|
||||
}
|
||||
if (parent in onlyValidChildren) {
|
||||
return onlyValidChildren[parent].has(child);
|
||||
}
|
||||
if (child in onlyValidParents) {
|
||||
return onlyValidParents[child].has(parent);
|
||||
}
|
||||
if (parent in knownInvalidChildren) {
|
||||
if (knownInvalidChildren[parent].has(child)) return false;
|
||||
}
|
||||
if (child in knownInvalidParents) {
|
||||
if (knownInvalidParents[child].has(parent)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
const headings = /* @__PURE__ */ new Set(["h1", "h2", "h3", "h4", "h5", "h6"]);
|
||||
const emptySet = /* @__PURE__ */ new Set([]);
|
||||
const onlyValidChildren = {
|
||||
head: /* @__PURE__ */ new Set([
|
||||
"base",
|
||||
"basefront",
|
||||
"bgsound",
|
||||
"link",
|
||||
"meta",
|
||||
"title",
|
||||
"noscript",
|
||||
"noframes",
|
||||
"style",
|
||||
"script",
|
||||
"template"
|
||||
]),
|
||||
optgroup: /* @__PURE__ */ new Set(["option"]),
|
||||
select: /* @__PURE__ */ new Set(["optgroup", "option", "hr"]),
|
||||
// table
|
||||
table: /* @__PURE__ */ new Set(["caption", "colgroup", "tbody", "tfoot", "thead"]),
|
||||
tr: /* @__PURE__ */ new Set(["td", "th"]),
|
||||
colgroup: /* @__PURE__ */ new Set(["col"]),
|
||||
tbody: /* @__PURE__ */ new Set(["tr"]),
|
||||
thead: /* @__PURE__ */ new Set(["tr"]),
|
||||
tfoot: /* @__PURE__ */ new Set(["tr"]),
|
||||
// these elements can not have any children elements
|
||||
script: emptySet,
|
||||
iframe: emptySet,
|
||||
option: emptySet,
|
||||
textarea: emptySet,
|
||||
style: emptySet,
|
||||
title: emptySet
|
||||
};
|
||||
const onlyValidParents = {
|
||||
// sections
|
||||
html: emptySet,
|
||||
body: /* @__PURE__ */ new Set(["html"]),
|
||||
head: /* @__PURE__ */ new Set(["html"]),
|
||||
// table
|
||||
td: /* @__PURE__ */ new Set(["tr"]),
|
||||
colgroup: /* @__PURE__ */ new Set(["table"]),
|
||||
caption: /* @__PURE__ */ new Set(["table"]),
|
||||
tbody: /* @__PURE__ */ new Set(["table"]),
|
||||
tfoot: /* @__PURE__ */ new Set(["table"]),
|
||||
col: /* @__PURE__ */ new Set(["colgroup"]),
|
||||
th: /* @__PURE__ */ new Set(["tr"]),
|
||||
thead: /* @__PURE__ */ new Set(["table"]),
|
||||
tr: /* @__PURE__ */ new Set(["tbody", "thead", "tfoot"]),
|
||||
// data list
|
||||
dd: /* @__PURE__ */ new Set(["dl", "div"]),
|
||||
dt: /* @__PURE__ */ new Set(["dl", "div"]),
|
||||
// other
|
||||
figcaption: /* @__PURE__ */ new Set(["figure"]),
|
||||
// li: new Set(["ul", "ol"]),
|
||||
summary: /* @__PURE__ */ new Set(["details"]),
|
||||
area: /* @__PURE__ */ new Set(["map"])
|
||||
};
|
||||
const knownInvalidChildren = {
|
||||
p: /* @__PURE__ */ new Set([
|
||||
"address",
|
||||
"article",
|
||||
"aside",
|
||||
"blockquote",
|
||||
"center",
|
||||
"details",
|
||||
"dialog",
|
||||
"dir",
|
||||
"div",
|
||||
"dl",
|
||||
"fieldset",
|
||||
"figure",
|
||||
"footer",
|
||||
"form",
|
||||
"h1",
|
||||
"h2",
|
||||
"h3",
|
||||
"h4",
|
||||
"h5",
|
||||
"h6",
|
||||
"header",
|
||||
"hgroup",
|
||||
"hr",
|
||||
"li",
|
||||
"main",
|
||||
"nav",
|
||||
"menu",
|
||||
"ol",
|
||||
"p",
|
||||
"pre",
|
||||
"section",
|
||||
"table",
|
||||
"ul"
|
||||
]),
|
||||
svg: /* @__PURE__ */ new Set([
|
||||
"b",
|
||||
"blockquote",
|
||||
"br",
|
||||
"code",
|
||||
"dd",
|
||||
"div",
|
||||
"dl",
|
||||
"dt",
|
||||
"em",
|
||||
"embed",
|
||||
"h1",
|
||||
"h2",
|
||||
"h3",
|
||||
"h4",
|
||||
"h5",
|
||||
"h6",
|
||||
"hr",
|
||||
"i",
|
||||
"img",
|
||||
"li",
|
||||
"menu",
|
||||
"meta",
|
||||
"ol",
|
||||
"p",
|
||||
"pre",
|
||||
"ruby",
|
||||
"s",
|
||||
"small",
|
||||
"span",
|
||||
"strong",
|
||||
"sub",
|
||||
"sup",
|
||||
"table",
|
||||
"u",
|
||||
"ul",
|
||||
"var"
|
||||
])
|
||||
};
|
||||
const knownInvalidParents = {
|
||||
a: /* @__PURE__ */ new Set(["a"]),
|
||||
button: /* @__PURE__ */ new Set(["button"]),
|
||||
dd: /* @__PURE__ */ new Set(["dd", "dt"]),
|
||||
dt: /* @__PURE__ */ new Set(["dd", "dt"]),
|
||||
form: /* @__PURE__ */ new Set(["form"]),
|
||||
li: /* @__PURE__ */ new Set(["li"]),
|
||||
h1: headings,
|
||||
h2: headings,
|
||||
h3: headings,
|
||||
h4: headings,
|
||||
h5: headings,
|
||||
h6: headings
|
||||
};
|
||||
|
||||
const validateHtmlNesting = (node, context) => {
|
||||
if (node.type === 1 && node.tagType === 0 && context.parent && context.parent.type === 1 && context.parent.tagType === 0 && !isValidHTMLNesting(context.parent.tag, node.tag)) {
|
||||
const error = new SyntaxError(
|
||||
`<${node.tag}> cannot be child of <${context.parent.tag}>, according to HTML specifications. This can cause hydration errors or potentially disrupt future functionality.`
|
||||
);
|
||||
error.loc = node.loc;
|
||||
context.onWarn(error);
|
||||
}
|
||||
};
|
||||
|
||||
const DOMNodeTransforms = [
|
||||
transformStyle,
|
||||
...!!(process.env.NODE_ENV !== "production") ? [transformTransition, validateHtmlNesting] : []
|
||||
];
|
||||
const DOMDirectiveTransforms = {
|
||||
cloak: noopDirectiveTransform,
|
||||
html: transformVHtml,
|
||||
text: transformVText,
|
||||
model: transformModel,
|
||||
// override compiler-core
|
||||
on: transformOn,
|
||||
// override compiler-core
|
||||
show: transformShow
|
||||
};
|
||||
function compile(src, options = {}) {
|
||||
return baseCompile(
|
||||
src,
|
||||
extend({}, parserOptions, options, {
|
||||
nodeTransforms: [
|
||||
// ignore <script> and <tag>
|
||||
// this is not put inside DOMNodeTransforms because that list is used
|
||||
// by compiler-ssr to generate vnode fallback branches
|
||||
ignoreSideEffectTags,
|
||||
...DOMNodeTransforms,
|
||||
...options.nodeTransforms || []
|
||||
],
|
||||
directiveTransforms: extend(
|
||||
{},
|
||||
DOMDirectiveTransforms,
|
||||
options.directiveTransforms || {}
|
||||
),
|
||||
transformHoist: null
|
||||
})
|
||||
);
|
||||
}
|
||||
function parse(template, options = {}) {
|
||||
return baseParse(template, extend({}, parserOptions, options));
|
||||
}
|
||||
|
||||
export { DOMDirectiveTransforms, DOMErrorCodes, DOMErrorMessages, DOMNodeTransforms, TRANSITION, TRANSITION_GROUP, V_MODEL_CHECKBOX, V_MODEL_DYNAMIC, V_MODEL_RADIO, V_MODEL_SELECT, V_MODEL_TEXT, V_ON_WITH_KEYS, V_ON_WITH_MODIFIERS, V_SHOW, compile, createDOMCompilerError, parse, parserOptions, transformStyle };
|
||||
+6814
File diff suppressed because it is too large.
Load diff
+14
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* @vue/compiler-dom v3.5.30
|
||||
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
||||
* @license MIT
|
||||
**/var VueCompilerDOM=function(e){"use strict";let t;function n(e){let t=Object.create(null);for(let n of e.split(","))t[n]=1;return e=>e in t}let i={},s=()=>{},r=()=>!1,o=e=>111===e.charCodeAt(0)&&110===e.charCodeAt(1)&&(e.charCodeAt(2)>122||97>e.charCodeAt(2)),a=Object.assign,l=Array.isArray,c=e=>"string"==typeof e,h=e=>"symbol"==typeof e,d=e=>null!==e&&"object"==typeof e,p=n(",key,ref,ref_for,ref_key,onVnodeBeforeMount,onVnodeMounted,onVnodeBeforeUpdate,onVnodeUpdated,onVnodeBeforeUnmount,onVnodeUnmounted"),u=n("bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text,memo"),f=e=>{let t=Object.create(null);return n=>t[n]||(t[n]=e(n))},E=/-\w/g,_=f(e=>e.replace(E,e=>e.slice(1).toUpperCase())),m=f(e=>e.charAt(0).toUpperCase()+e.slice(1)),S=f(e=>e?`on${m(e)}`:""),g=/;(?![^(]*\))/g,T=/:([^]+)/,N=/\/\*[^]*?\*\//g,I=n("html,body,base,head,link,meta,style,title,address,article,aside,footer,header,hgroup,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,output,progress,select,textarea,details,dialog,menu,summary,template,blockquote,iframe,tfoot"),y=n("svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer,feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,feDistantLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,text,textPath,title,tspan,unknown,use,view"),O=n("annotation,annotation-xml,maction,maligngroup,malignmark,math,menclose,merror,mfenced,mfrac,mfraction,mglyph,mi,mlabeledtr,mlongdiv,mmultiscripts,mn,mo,mover,mpadded,mphantom,mprescripts,mroot,mrow,ms,mscarries,mscarry,msgroup,msline,mspace,msqrt,msrow,mstack,mstyle,msub,msubsup,msup,mtable,mtd,mtext,mtr,munder,munderover,none,semantics"),A=n("area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr"),C=Symbol(""),b=Symbol(""),v=Symbol(""),R=Symbol(""),x=Symbol(""),L=Symbol(""),M=Symbol(""),D=Symbol(""),P=Symbol(""),V=Symbol(""),k=Symbol(""),X=Symbol(""),w=Symbol(""),U=Symbol(""),F=Symbol(""),B=Symbol(""),$=Symbol(""),H=Symbol(""),G=Symbol(""),q=Symbol(""),J=Symbol(""),j=Symbol(""),W=Symbol(""),K=Symbol(""),Y=Symbol(""),Q=Symbol(""),z=Symbol(""),Z=Symbol(""),ee=Symbol(""),et=Symbol(""),en=Symbol(""),ei=Symbol(""),es=Symbol(""),er=Symbol(""),eo=Symbol(""),ea=Symbol(""),el=Symbol(""),ec=Symbol(""),eh=Symbol(""),ed={[C]:"Fragment",[b]:"Teleport",[v]:"Suspense",[R]:"KeepAlive",[x]:"BaseTransition",[L]:"openBlock",[M]:"createBlock",[D]:"createElementBlock",[P]:"createVNode",[V]:"createElementVNode",[k]:"createCommentVNode",[X]:"createTextVNode",[w]:"createStaticVNode",[U]:"resolveComponent",[F]:"resolveDynamicComponent",[B]:"resolveDirective",[$]:"resolveFilter",[H]:"withDirectives",[G]:"renderList",[q]:"renderSlot",[J]:"createSlots",[j]:"toDisplayString",[W]:"mergeProps",[K]:"normalizeClass",[Y]:"normalizeStyle",[Q]:"normalizeProps",[z]:"guardReactiveProps",[Z]:"toHandlers",[ee]:"camelize",[et]:"capitalize",[en]:"toHandlerKey",[ei]:"setBlockTracking",[es]:"pushScopeId",[er]:"popScopeId",[eo]:"withCtx",[ea]:"unref",[el]:"isRef",[ec]:"withMemo",[eh]:"isMemoSame"};function ep(e){Object.getOwnPropertySymbols(e).forEach(t=>{ed[t]=e[t]})}let eu={start:{line:1,column:1,offset:0},end:{line:1,column:1,offset:0},source:""};function ef(e,t=""){return{type:0,source:t,children:e,helpers:new Set,components:[],directives:[],hoists:[],imports:[],cached:[],temps:0,codegenNode:void 0,loc:eu}}function eE(e,t,n,i,s,r,o,a=!1,l=!1,c=!1,h=eu){return e&&(a?(e.helper(L),e.helper(eb(e.inSSR,c))):e.helper(eC(e.inSSR,c)),o&&e.helper(H)),{type:13,tag:t,props:n,children:i,patchFlag:s,dynamicProps:r,directives:o,isBlock:a,disableTracking:l,isComponent:c,loc:h}}function e_(e,t=eu){return{type:17,loc:t,elements:e}}function em(e,t=eu){return{type:15,loc:t,properties:e}}function eS(e,t){return{type:16,loc:eu,key:c(e)?eg(e,!0):e,value:t}}function eg(e,t=!1,n=eu,i=0){return{type:4,loc:n,content:e,isStatic:t,constType:t?3:i}}function eT(e,t=eu){return{type:8,loc:t,children:e}}function eN(e,t=[],n=eu){return{type:14,loc:n,callee:e,arguments:t}}function eI(e,t,n=!1,i=!1,s=eu){return{type:18,params:e,returns:t,newline:n,isSlot:i,loc:s}}function ey(e,t,n,i=!0){return{type:19,test:e,consequent:t,alternate:n,newline:i,loc:eu}}function eO(e,t,n=!1,i=!1){return{type:20,index:e,valuLine truncated
|
||||
Use a v-bind binding combined with a v-on listener that emits update:x event instead.`,45:"v-model cannot be used on a const binding because it is not writable.",46:"Error parsing JavaScript expression: ",47:"<KeepAlive> expects exactly one child component.",52:"@vnode-* hooks in templates are no longer supported. Use the vue: prefix instead. For example, @vnode-mounted should be changed to @vue:mounted. @vnode-* hooks support has been removed in 3.4.",48:'"prefixIdentifiers" option is not supported in this build of compiler.',49:"ES module mode is not supported in this build of compiler.",50:'"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.',51:'"scopeId" option is only supported in module mode.',54:""};function eH(e,t=[]){switch(e.type){case"Identifier":t.push(e);break;case"MemberExpression":let n=e;for(;"MemberExpression"===n.type;)n=n.object;t.push(n);break;case"ObjectPattern":for(let n of e.properties)"RestElement"===n.type?eH(n.argument,t):eH(n.value,t);break;case"ArrayPattern":e.elements.forEach(e=>{e&&eH(e,t)});break;case"RestElement":eH(e.argument,t);break;case"AssignmentPattern":eH(e.left,t)}return t}let eG=e=>e&&("ObjectProperty"===e.type||"ObjectMethod"===e.type)&&!e.computed,eq=["TSAsExpression","TSTypeAssertion","TSNonNullExpression","TSInstantiationExpression","TSSatisfiesExpression"],eJ=e=>4===e.type&&e.isStatic;function ej(e){switch(e){case"Teleport":case"teleport":return b;case"Suspense":case"suspense":return v;case"KeepAlive":case"keep-alive":return R;case"BaseTransition":case"base-transition":return x}}let eW=/^$|^\d|[^\$\w\xA0-\uFFFF]/,eK=e=>!eW.test(e),eY=/[A-Za-z_$\xA0-\uFFFF]/,eQ=/[\.\?\w$\xA0-\uFFFF]/,ez=/\s+[.[]\s*|\s*[.[]\s+/g,eZ=e=>4===e.type?e.content:e.loc.source,e1=e=>{let t=eZ(e).trim().replace(ez,e=>e.trim()),n=0,i=[],s=0,r=0,o=null;for(let e=0;e<t.length;e++){let a=t.charAt(e);switch(n){case 0:if("["===a)i.push(n),n=1,s++;else if("("===a)i.push(n),n=2,r++;else if(!(0===e?eY:eQ).test(a))return!1;break;case 1:"'"===a||'"'===a||"`"===a?(i.push(n),n=3,o=a):"["===a?s++:"]"!==a||--s||(n=i.pop());break;case 2:if("'"===a||'"'===a||"`"===a)i.push(n),n=3,o=a;else if("("===a)r++;else if(")"===a){if(e===t.length-1)return!1;--r||(n=i.pop())}break;case 3:a===o&&(n=i.pop(),o=null)}}return!s&&!r},e0=/^\s*(?:async\s*)?(?:\([^)]*?\)|[\w$_]+)\s*(?::[^=]+)?=>|^\s*(?:async\s+)?function(?:\s+[\w$]+)?\s*\(/,e2=e=>e0.test(eZ(e));function e3(e,t,n=t.length){let i=0,s=-1;for(let e=0;e<n;e++)10===t.charCodeAt(e)&&(i++,s=e);return e.offset+=n,e.line+=i,e.column=-1===s?e.column+n:n-s,e}function e4(e,t,n=!1){for(let i=0;i<e.props.length;i++){let s=e.props[i];if(7===s.type&&(n||s.exp)&&(c(t)?s.name===t:t.test(s.name)))return s}}function e6(e,t,n=!1,i=!1){for(let s=0;s<e.props.length;s++){let r=e.props[s];if(6===r.type){if(n)continue;if(r.name===t&&(r.value||i))return r}else if("bind"===r.name&&(r.exp||i)&&e5(r.arg,t))return r}}function e5(e,t){return!!(e&&eJ(e)&&e.content===t)}function e9(e){return e.props.some(e=>7===e.type&&"bind"===e.name&&(!e.arg||4!==e.arg.type||!e.arg.isStatic))}function e7(e){return 5===e.type||2===e.type}function e8(e){return 7===e.type&&"pre"===e.name}function te(e){return 7===e.type&&"slot"===e.name}function tt(e){return 1===e.type&&3===e.tagType}function tn(e){return 1===e.type&&2===e.tagType}let ti=new Set([Q,z]);function ts(e,t,n){let i,s,r=13===e.type?e.props:e.arguments[2],o=[];if(r&&!c(r)&&14===r.type){let e=function e(t,n=[]){if(t&&!c(t)&&14===t.type){let i=t.callee;if(!c(i)&&ti.has(i))return e(t.arguments[0],n.concat(t))}return[t,n]}(r);r=e[0],s=(o=e[1])[o.length-1]}if(null==r||c(r))i=em([t]);else if(14===r.type){let e=r.arguments[0];c(e)||15!==e.type?r.callee===Z?i=eN(n.helper(W),[em([t]),r]):r.arguments.unshift(em([t])):tr(t,e)||e.properties.unshift(t),i||(i=r)}else 15===r.type?(tr(t,r)||r.properties.unshift(t),i=r):(i=eN(n.helper(W),[em([t]),r]),s&&s.callee===z&&(s=o[o.length-2]));13===e.type?s?s.arguments[0]=i:e.props=i:s?s.arguments[0]=i:e.arguments[2]=i}function tr(e,t){let n=!1;if(4===e.key.type){let i=e.key.content;n=t.properties.some(e=>4===e.key.type&&e.key.content===i)}return n}function to(e,t){return`_${t}_${e.replace(/[^\w]/g,(t,n)=>"-"===t?"_":e.charCodeAt(n).toString())}`}function ta(e){return 14===e.type&&e.callee===ec?e.arguments[1].returns:e}let tl=/([\s\S]*?)\s+(?:in|of)\s+(\S[\s\S]*)/;function tc(e){for(let t=0;t<e.length;t++)if(!eM(e.charCodeAt(t)))return!1;return!0}function th(e){return 2===e.type&&tc(e.content)||12===e.type&&th(e.content)}function td(e){return 3===e.type||th(e)}let tp={parseMode:"base",ns:0,delimiters:["{{","}}"],getNamespace:()=>0,isVoidTag:r,isPreTag:r,isIgnoreNewlineTag:r,isCustomElement:r,onError:eU,onWarn:eF,comments:!1,prefixIdentifiers:!1},tu=tp,tf=null,tE="",t_=null,tm=null,tS="",tg=-1,tT=-1,tN=0,tI=!1,ty=null,tO=[],tA=new class{constructor(e,t){this.stack=e,this.cbs=t,this.state=1,this.buffer="",this.sectionStart=0,this.index=0,this.entityStart=0,this.baseState=1,this.inRCDATA=!1,t
Line truncated
|
||||
`);else if(tc(s.content)){let r=e[i-1]&&e[i-1].type,o=e[i+1]&&e[i+1].type;!r||!o||t&&(3===r&&(3===o||1===o)||1===r&&(3===o||1===o&&function(e){for(let t=0;t<e.length;t++){let n=e.charCodeAt(t);if(10===n||13===n)return!0}return!1}(s.content)))?(n=!0,e[i]=null):s.content=" "}else t&&(s.content=tX(s.content))}return n?e.filter(Boolean):e}function tX(e){let t="",n=!1;for(let i=0;i<e.length;i++)eM(e.charCodeAt(i))?n||(t+=" ",n=!0):(t+=e[i],n=!1);return t}function tw(e){(tO[0]||tf).children.push(e)}function tU(e,t){return{start:tA.getPos(e),end:null==t?t:tA.getPos(t),source:null==t?t:tv(e,t)}}function tF(e,t){e.end=tA.getPos(t),e.source=tv(e.start.offset,t)}function tB(e,t=!1,n,i=0,s=0){return eg(e,t,n,i)}function t$(e,t,n){tu.onError(eB(e,tU(t,t)))}function tH(e,t){if(tA.reset(),t_=null,tm=null,tS="",tg=-1,tT=-1,tO.length=0,tE=e,tu=a({},tp),t){let e;for(e in t)null!=t[e]&&(tu[e]=t[e])}tA.mode="html"===tu.parseMode?1:2*("sfc"===tu.parseMode),tA.inXML=1===tu.ns||2===tu.ns;let n=t&&t.delimiters;n&&(tA.delimiterOpen=eP(n[0]),tA.delimiterClose=eP(n[1]));let i=tf=ef([],e);return tA.parse(tE),i.loc=tU(0,e.length),i.children=tk(i.children),tf=null,i}function tG(e){let t=e.children.filter(e=>3!==e.type);return 1!==t.length||1!==t[0].type||tn(t[0])?null:t[0]}function tq(e,t){let{constantCache:n}=t;switch(e.type){case 1:if(0!==e.tagType)return 0;let i=n.get(e);if(void 0!==i)return i;let s=e.codegenNode;if(13!==s.type||s.isBlock&&"svg"!==e.tag&&"foreignObject"!==e.tag&&"math"!==e.tag)return 0;if(void 0!==s.patchFlag)return n.set(e,0),0;{let i=3,r=tj(e,t);if(0===r)return n.set(e,0),0;r<i&&(i=r);for(let s=0;s<e.children.length;s++){let r=tq(e.children[s],t);if(0===r)return n.set(e,0),0;r<i&&(i=r)}if(i>1)for(let s=0;s<e.props.length;s++){let r=e.props[s];if(7===r.type&&"bind"===r.name&&r.exp){let s=tq(r.exp,t);if(0===s)return n.set(e,0),0;s<i&&(i=s)}}if(s.isBlock){for(let t=0;t<e.props.length;t++)if(7===e.props[t].type)return n.set(e,0),0;t.removeHelper(L),t.removeHelper(eb(t.inSSR,s.isComponent)),s.isBlock=!1,t.helper(eC(t.inSSR,s.isComponent))}return n.set(e,i),i}case 2:case 3:return 3;case 9:case 11:case 10:default:return 0;case 5:case 12:return tq(e.content,t);case 4:return e.constType;case 8:let r=3;for(let n=0;n<e.children.length;n++){let i=e.children[n];if(c(i)||h(i))continue;let s=tq(i,t);if(0===s)return 0;s<r&&(r=s)}return r;case 20:return 2}}let tJ=new Set([K,Y,Q,z]);function tj(e,t){let n=3,i=tW(e);if(i&&15===i.type){let{properties:e}=i;for(let i=0;i<e.length;i++){let s,{key:r,value:o}=e[i],a=tq(r,t);if(0===a)return a;if(a<n&&(n=a),0===(s=4===o.type?tq(o,t):14===o.type?function e(t,n){if(14===t.type&&!c(t.callee)&&tJ.has(t.callee)){let i=t.arguments[0];if(4===i.type)return tq(i,n);if(14===i.type)return e(i,n)}return 0}(o,t):0))return s;s<n&&(n=s)}}return n}function tW(e){let t=e.codegenNode;if(13===t.type)return t.props}function tK(e,{filename:t="",prefixIdentifiers:n=!1,hoistStatic:r=!1,hmr:o=!1,cacheHandlers:a=!1,nodeTransforms:l=[],directiveTransforms:h={},transformHoist:d=null,isBuiltInComponent:p=s,isCustomElement:u=s,expressionPlugins:f=[],scopeId:E=null,slotted:S=!0,ssr:g=!1,inSSR:T=!1,ssrCssVars:N="",bindingMetadata:I=i,inline:y=!1,isTS:O=!1,onError:A=eU,onWarn:C=eF,compatConfig:b}){let v=t.replace(/\?.*$/,"").match(/([^/\\]+)\.\w+$/),R={filename:t,selfName:v&&m(_(v[1])),prefixIdentifiers:n,hoistStatic:r,hmr:o,cacheHandlers:a,nodeTransforms:l,directiveTransforms:h,transformHoist:d,isBuiltInComponent:p,isCustomElement:u,expressionPlugins:f,scopeId:E,slotted:S,ssr:g,inSSR:T,ssrCssVars:N,bindingMetadata:I,inline:y,isTS:O,onError:A,onWarn:C,compatConfig:b,root:e,helpers:new Map,components:new Set,directives:new Set,hoists:[],imports:[],cached:[],constantCache:new WeakMap,temps:0,identifiers:Object.create(null),scopes:{vFor:0,vSlot:0,vPre:0,vOnce:0},parent:null,grandParent:null,currentNode:e,childIndex:0,inVOnce:!1,helper(e){let t=R.helpers.get(e)||0;return R.helpers.set(e,t+1),e},removeHelper(e){let t=R.helpers.get(e);if(t){let n=t-1;n?R.helpers.set(e,n):R.helpers.delete(e)}},helperString:e=>`_${ed[R.helper(e)]}`,replaceNode(e){R.parent.children[R.childIndex]=R.currentNode=e},removeNode(e){let t=R.parent.children,n=e?t.indexOf(e):R.currentNode?R.childIndex:-1;e&&e!==R.currentNode?R.childIndex>n&&(R.childIndex--,R.onNodeRemoved()):(R.currentNode=null,R.onNodeRemoved()),R.parent.children.splice(n,1)},onNodeRemoved:s,addIdentifiers(e){},removeIdentifiers(e){},hoist(e){c(e)&&(e=eg(e)),R.hoists.push(e);let t=eg(`_hoisted_${R.hoists.length}`,!1,e.loc,2);return t.hoisted=e,t},cache(e,t=!1,n=!1){let i=eO(R.cached.length,e,t,n);return R.cached.push(i),i}};return R.filters=new Set,R}function tY(e,t){let n=tK(e,t);tQ(e,n),t.hoistStatic&&function e(t,n,i,s=!1,r=!1){let{children:o}=t,a=[];for(let n=0;n<o.length;n++){let l=o[n];if(1===l.type&&0===l.tagType){let e=s?0:tq(l,i);if(e>0){if(e>=2){l.codegenNode.patchFlag=-1,a.push(l);continue}}else{let e=l.codegenNode;if(13===e.type){let t=e.patchFlag;if((void 0===t||512===t||1===
Line truncated
|
||||
`+" ".repeat(e),0)}return u}(e,t);t.onContextCreated&&t.onContextCreated(n);let{mode:i,push:s,prefixIdentifiers:r,indent:o,deindent:a,newline:l,ssr:c}=n,h=Array.from(e.helpers),d=h.length>0,p=!r&&"module"!==i;!function(e,t){let{push:n,newline:i,runtimeGlobalName:s}=t,r=Array.from(e.helpers);if(r.length>0&&(n(`const _Vue = ${s}
|
||||
`,-1),e.hoists.length)){let e=[P,V,k,X,w].filter(e=>r.includes(e)).map(t1).join(", ");n(`const { ${e} } = _Vue
|
||||
`,-1)}(function(e,t){if(!e.length)return;t.pure=!0;let{push:n,newline:i}=t;i();for(let s=0;s<e.length;s++){let r=e[s];r&&(n(`const _hoisted_${s+1} = `),t6(r,t),i())}t.pure=!1})(e.hoists,t),i(),n("return ")}(e,n);let u=(c?["_ctx","_push","_parent","_attrs"]:["_ctx","_cache"]).join(", ");if(s(`function ${c?"ssrRender":"render"}(${u}) {`),o(),p&&(s("with (_ctx) {"),o(),d&&(s(`const { ${h.map(t1).join(", ")} } = _Vue
|
||||
`,-1),l())),e.components.length&&(t2(e.components,"component",n),(e.directives.length||e.temps>0)&&l()),e.directives.length&&(t2(e.directives,"directive",n),e.temps>0&&l()),e.filters&&e.filters.length&&(l(),t2(e.filters,"filter",n),l()),e.temps>0){s("let ");for(let t=0;t<e.temps;t++)s(`${t>0?", ":""}_temp${t}`)}return(e.components.length||e.directives.length||e.temps)&&(s(`
|
||||
`,0),l()),c||s("return "),e.codegenNode?t6(e.codegenNode,n):s("null"),p&&(a(),s("}")),a(),s("}"),{ast:e,code:n.code,preamble:"",map:n.map?n.map.toJSON():void 0}}function t2(e,t,{helper:n,push:i,newline:s,isTS:r}){let o=n("filter"===t?$:"component"===t?U:B);for(let n=0;n<e.length;n++){let a=e[n],l=a.endsWith("__self");l&&(a=a.slice(0,-6)),i(`const ${to(a,t)} = ${o}(${JSON.stringify(a)}${l?", true":""})${r?"!":""}`),n<e.length-1&&s()}}function t3(e,t){let n=e.length>3;t.push("["),n&&t.indent(),t4(e,t,n),n&&t.deindent(),t.push("]")}function t4(e,t,n=!1,i=!0){let{push:s,newline:r}=t;for(let o=0;o<e.length;o++){let a=e[o];c(a)?s(a,-3):l(a)?t3(a,t):t6(a,t),o<e.length-1&&(n?(i&&s(","),r()):i&&s(", "))}}function t6(e,t){var n,i,s;if(c(e))return void t.push(e,-3);if(h(e))return void t.push(t.helper(e));switch(e.type){case 1:case 9:case 11:case 12:t6(e.codegenNode,t);break;case 2:n=e,t.push(JSON.stringify(n.content),-3,n);break;case 4:t5(e,t);break;case 5:!function(e,t){let{push:n,helper:i,pure:s}=t;s&&n(tZ),n(`${i(j)}(`),t6(e.content,t),n(")")}(e,t);break;case 8:t9(e,t);break;case 3:!function(e,t){let{push:n,helper:i,pure:s}=t;s&&n(tZ),n(`${i(k)}(${JSON.stringify(e.content)})`,-3,e)}(e,t);break;case 13:!function(e,t){let n,{push:i,helper:s,pure:r}=t,{tag:o,props:a,children:l,patchFlag:c,dynamicProps:h,directives:d,isBlock:p,disableTracking:u,isComponent:f}=e;c&&(n=String(c)),d&&i(s(H)+"("),p&&i(`(${s(L)}(${u?"true":""}), `),r&&i(tZ),i(s(p?eb(t.inSSR,f):eC(t.inSSR,f))+"(",-2,e),t4(function(e){let t=e.length;for(;t--&&null==e[t];);return e.slice(0,t+1).map(e=>e||"null")}([o,a,l,n,h]),t),i(")"),p&&i(")"),d&&(i(", "),t6(d,t),i(")"))}(e,t);break;case 14:!function(e,t){let{push:n,helper:i,pure:s}=t,r=c(e.callee)?e.callee:i(e.callee);s&&n(tZ),n(r+"(",-2,e),t4(e.arguments,t),n(")")}(e,t);break;case 15:!function(e,t){let{push:n,indent:i,deindent:s,newline:r}=t,{properties:o}=e;if(!o.length)return n("{}",-2,e);let a=o.length>1;n(a?"{":"{ "),a&&i();for(let e=0;e<o.length;e++){let{key:i,value:s}=o[e];!function(e,t){let{push:n}=t;8===e.type?(n("["),t9(e,t),n("]")):e.isStatic?n(eK(e.content)?e.content:JSON.stringify(e.content),-2,e):n(`[${e.content}]`,-3,e)}(i,t),n(": "),t6(s,t),e<o.length-1&&(n(","),r())}a&&s(),n(a?"}":" }")}(e,t);break;case 17:i=e,s=t,t3(i.elements,s);break;case 18:!function(e,t){let{push:n,indent:i,deindent:s}=t,{params:r,returns:o,body:a,newline:c,isSlot:h}=e;h&&n(`_${ed[eo]}(`),n("(",-2,e),l(r)?t4(r,t):r&&t6(r,t),n(") => "),(c||a)&&(n("{"),i()),o?(c&&n("return "),l(o)?t3(o,t):t6(o,t)):a&&t6(a,t),(c||a)&&(s(),n("}")),h&&(e.isNonScopedSlot&&n(", undefined, true"),n(")"))}(e,t);break;case 19:!function(e,t){let{test:n,consequent:i,alternate:s,newline:r}=e,{push:o,indent:a,deindent:l,newline:c}=t;if(4===n.type){let e=!eK(n.content);e&&o("("),t5(n,t),e&&o(")")}else o("("),t6(n,t),o(")");r&&a(),t.indentLevel++,r||o(" "),o("? "),t6(i,t),t.indentLevel--,r&&c(),r||o(" "),o(": ");let h=19===s.type;!h&&t.indentLevel++,t6(s,t),!h&&t.indentLevel--,r&&l(!0)}(e,t);break;case 20:!function(e,t){let{push:n,helper:i,indent:s,deindent:r,newline:o}=t,{needPauseTracking:a,needArraySpread:l}=e;l&&n("[...("),n(`_cache[${e.index}] || (`),a&&(s(),n(`${i(ei)}(-1`),e.inVOnce&&n(", true"),n("),"),o(),n("(")),n(`_cache[${e.index}] = `),t6(e.value,t),a&&(n(`).cacheIndex = ${e.index},`),o(),n(`${i(ei)}(1),`),o(),n(`_cache[${e.index}]`),r()),n(")"),l&&n(")]")}(e,t);break;case 21:t4(e.body,t,!0,!1)}}function t5(e,t){let{content:n,isStatic:i}=e;t.push(i?JSON.stringify(n):n,-3,e)}function t9(e,t){for(let n=0;n<e.children.length;n++){let i=e.children[n];c(i)?t.push(i,-3):t6(i,t)}}function t7(e,t,n=!1,i=!1,s=Object.create(t.identifiers)){return e}let t8=tz(/^(?:if|else|else-if)$/,(e,t,n)=>ne(e,t,n,(e,t,i)=>{let s=n.parent.children,r=s.indexOf(e),o=0;for(;r-- >=0;){let e=s[r];e&&9===e.type&&(o+=e.branches.length)}return()=>{i?e.codegenNode=nn(t,o,n):function(e){for(;;)if(19===e.type)if(19!==e.alternate.type)return e;else e=e.alternate;else 20===e.type&&(e=e.value)}(e.codegenNode).alternate=nn(t,o+e.branches.length-1,n)}}));function ne(e,t,n,i){if("else"!==t.name&&(!t.exp||!t.exp.content.trim())){let i=t.exp?t.exp.loc:e.loc;n.onError(eB(28,t.loc)),t.exp=eg("true",!1,i)}if("if"===t.name){var s;let r=nt(e,t),o={type:9,loc:tU((s=e.loc).start.offset,s.end.offset),branches:[r]};if(n.replaceNode(o),i)return i(o,r,!0)}else{let s=n.parent.children,r=s.indexOf(e);for(;r-- >=-1;){let o=s[r];if(o&&td(o)){n.removeNode(o);continue}if(o&&9===o.type){("else-if"===t.name||"else"===t.name)&&void 0===o.branches[o.branches.length-1].condition&&n.onError(eB(30,e.loc)),n.removeNode();let s=nt(e,t);o.branches.push(s);let r=i&&i(o,s,!1);tQ(s,n),r&&r(),n.currentNode=null}else n.onError(eB(30,e.loc));break}}}function nt(e,t){let n=3===e.tagType;return{type:10,loc:e.loc,condition:"else"===t.name?void 0:t.exp,children:n&&!e4(e,"for")?e.children:[e],userKey:e6(e,"key"),isTemplateIf:n}}function nn(e,t,n){return e.condition?ey(e.condition,ni(e,t,n),eN(n.helper(k),['""',"true"]
Line truncated
|
||||
`)},e.getBaseTransformPreset=nX,e.getConstantType=tq,e.getMemoedVNodeCall=ta,e.getVNodeBlockHelper=eb,e.getVNodeHelper=eC,e.hasDynamicKeyVBind=e9,e.hasScopeRef=function e(t,n){if(!t||0===Object.keys(n).length)return!1;switch(t.type){case 1:for(let i=0;i<t.props.length;i++){let s=t.props[i];if(7===s.type&&(e(s.arg,n)||e(s.exp,n)))return!0}return t.children.some(t=>e(t,n));case 11:if(e(t.source,n))return!0;return t.children.some(t=>e(t,n));case 9:return t.branches.some(t=>e(t,n));case 10:if(e(t.condition,n))return!0;return t.children.some(t=>e(t,n));case 4:return!t.isStatic&&eK(t.content)&&!!n[t.content];case 8:return t.children.some(t=>d(t)&&e(t,n));case 5:case 12:return e(t.content,n);default:return!1}},e.helperNameMap=ed,e.injectProp=ts,e.isAllWhitespace=tc,e.isCommentOrWhitespace=td,e.isCoreComponent=ej,e.isFnExpression=e2,e.isFnExpressionBrowser=e2,e.isFnExpressionNode=s,e.isFunctionType=e=>/Function(?:Expression|Declaration)$|Method$/.test(e.type),e.isInDestructureAssignment=function(e,t){if(e&&("ObjectProperty"===e.type||"ArrayPattern"===e.type)){let e=t.length;for(;e--;){let n=t[e];if("AssignmentExpression"===n.type)return!0;if("ObjectProperty"!==n.type&&!n.type.endsWith("Pattern"))break}}return!1},e.isInNewExpression=function(e){let t=e.length;for(;t--;){let n=e[t];if("NewExpression"===n.type)return!0;if("MemberExpression"!==n.type)break}return!1},e.isMemberExpression=e1,e.isMemberExpressionBrowser=e1,e.isMemberExpressionNode=s,e.isReferencedIdentifier=function(e,t,n){return!1},e.isSimpleIdentifier=eK,e.isSlotOutlet=tn,e.isStaticArgOf=e5,e.isStaticExp=eJ,e.isStaticProperty=eG,e.isStaticPropertyKey=(e,t)=>eG(t)&&t.key===e,e.isTemplateNode=tt,e.isText=e7,e.isVPre=e8,e.isVSlot=te,e.isWhitespaceText=th,e.locStub=eu,e.noopDirectiveTransform=nU,e.parse=function(e,t={}){return tH(e,a({},nY,t))},e.parserOptions=nY,e.processExpression=t7,e.processFor=nr,e.processIf=ne,e.processSlotOutlet=nN,e.registerRuntimeHelpers=ep,e.resolveComponentType=nE,e.stringifyExpression=function e(t){return c(t)?t:4===t.type?t.content:t.children.map(e).join("")},e.toValidAssetId=to,e.trackSlotScopes=nc,e.trackVForSlotScopes=(e,t)=>{let n;if(tt(e)&&e.props.some(te)&&(n=e4(e,"for"))){let e=n.forParseResult;if(e){no(e);let{value:n,key:i,index:s}=e,{addIdentifiers:r,removeIdentifiers:o}=t;return n&&r(n),i&&r(i),s&&r(s),()=>{n&&o(n),i&&o(i),s&&o(s)}}}},e.transform=tY,e.transformBind=ny,e.transformElement=nf,e.transformExpression=(e,t)=>{if(5===e.type)e.content=t7(e.content,t);else if(1===e.type){let n=e4(e,"memo");for(let i=0;i<e.props.length;i++){let s=e.props[i];if(7===s.type&&"for"!==s.name){let e=s.exp,i=s.arg;!e||4!==e.type||"on"===s.name&&i||n&&i&&4===i.type&&"key"===i.content||(s.exp=t7(e,t,"slot"===s.name)),i&&4===i.type&&!i.isStatic&&(s.arg=t7(i,t))}}}},e.transformModel=nv,e.transformOn=nI,e.transformStyle=nQ,e.transformVBindShorthand=nk,e.traverseNode=tQ,e.unwrapTSNode=function e(t){return eq.includes(t.type)?e(t.expression):t},e.validFirstIdentCharRE=eY,e.walkBlockDeclarations=function e(t,n){for(let s of"SwitchCase"===t.type?t.consequent:t.body)if("VariableDeclaration"===s.type){if(s.declare)continue;for(let e of s.declarations)for(let t of eH(e.id))n(t)}else if("FunctionDeclaration"===s.type||"ClassDeclaration"===s.type){if(s.declare||!s.id)continue;n(s.id)}else{var i;"ForOfStatement"===(i=s).type||"ForInStatement"===i.type||"ForStatement"===i.type?function(e,t,n){let i="ForStatement"===e.type?e.init:e.left;if(i&&"VariableDeclaration"===i.type&&("var"===i.kind?t:!t))for(let e of i.declarations)for(let t of eH(e.id))n(t)}(s,!0,n):"SwitchStatement"===s.type&&function(t,n,i){for(let s of t.cases){for(let e of s.consequent)if("VariableDeclaration"===e.type&&("var"===e.kind?n:!n))for(let t of e.declarations)for(let e of eH(t.id))i(e);e(s,i)}}(s,!0,n)}},e.walkFunctionParams=function(e,t){for(let n of e.params)for(let e of eH(n))t(e)},e.walkIdentifiers=function(e,t,n=!1,i=[],s=Object.create(null)){},e.warnDeprecation=function(e,t,n,...i){if("suppress-warning"===eX(e,t))return;let{message:s,link:r}=ek[e],o=SyntaxError(`(deprecation ${e}) ${"function"==typeof s?s(...i):s}${r?`
|
||||
Details: ${r}`:""}`);o.code=e,n&&(o.loc=n),t.onWarn(o)},e}({});
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
module.exports = require('./dist/compiler-dom.cjs.prod.js')
|
||||
} else {
|
||||
module.exports = require('./dist/compiler-dom.cjs.js')
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
{
|
||||
"name": "@vue/compiler-dom",
|
||||
"version": "3.5.30",
|
||||
"description": "@vue/compiler-dom",
|
||||
"main": "index.js",
|
||||
"module": "dist/compiler-dom.esm-bundler.js",
|
||||
"types": "dist/compiler-dom.d.ts",
|
||||
"unpkg": "dist/compiler-dom.global.js",
|
||||
"jsdelivr": "dist/compiler-dom.global.js",
|
||||
"files": [
|
||||
"index.js",
|
||||
"dist"
|
||||
],
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/compiler-dom.d.ts",
|
||||
"node": {
|
||||
"production": "./dist/compiler-dom.cjs.prod.js",
|
||||
"development": "./dist/compiler-dom.cjs.js",
|
||||
"default": "./index.js"
|
||||
},
|
||||
"module": "./dist/compiler-dom.esm-bundler.js",
|
||||
"import": "./dist/compiler-dom.esm-bundler.js",
|
||||
"require": "./index.js"
|
||||
},
|
||||
"./*": "./*"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"buildOptions": {
|
||||
"name": "VueCompilerDOM",
|
||||
"compat": true,
|
||||
"formats": [
|
||||
"esm-bundler",
|
||||
"esm-browser",
|
||||
"cjs",
|
||||
"global"
|
||||
]
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/vuejs/core.git",
|
||||
"directory": "packages/compiler-dom"
|
||||
},
|
||||
"keywords": [
|
||||
"vue"
|
||||
],
|
||||
"author": "Evan You",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/vuejs/core/issues"
|
||||
},
|
||||
"homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-dom#readme",
|
||||
"dependencies": {
|
||||
"@vue/shared": "3.5.30",
|
||||
"@vue/compiler-core": "3.5.30"
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2018-present, Yuxi (Evan) You
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
# @vue/compiler-sfc
|
||||
|
||||
> Lower level utilities for compiling Vue Single File Components
|
||||
|
||||
**Note: as of 3.2.13+, this package is included as a dependency of the main `vue` package and can be accessed as `vue/compiler-sfc`. This means you no longer need to explicitly install this package and ensure its version matches that of `vue`'s. Just use the main `vue/compiler-sfc` deep import instead.**
|
||||
|
||||
This package contains lower level utilities that you can use if you are writing a plugin / transform for a bundler or module system that compiles Vue Single File Components (SFCs) into JavaScript. It is used in [vue-loader](https://github.com/vuejs/vue-loader) and [@vitejs/plugin-vue](https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue).
|
||||
|
||||
## API
|
||||
|
||||
The API is intentionally low-level due to the various considerations when integrating Vue SFCs in a build system:
|
||||
|
||||
- Separate hot-module replacement (HMR) for script, template and styles
|
||||
- template updates should not reset component state
|
||||
- style updates should be performed without component re-render
|
||||
|
||||
- Leveraging the tool's plugin system for pre-processor handling. e.g. `<style lang="scss">` should be processed by the corresponding webpack loader.
|
||||
|
||||
- In some cases, transformers of each block in an SFC do not share the same execution context. For example, when used with `thread-loader` or other parallelized configurations, the template sub-loader in `vue-loader` may not have access to the full SFC and its descriptor.
|
||||
|
||||
The general idea is to generate a facade module that imports the individual blocks of the component. The trick is the module imports itself with different query strings so that the build system can handle each request as "virtual" modules:
|
||||
|
||||
```
|
||||
+--------------------+
|
||||
| |
|
||||
| script transform |
|
||||
+----->+ |
|
||||
| +--------------------+
|
||||
|
|
||||
+--------------------+ | +--------------------+
|
||||
| | | | |
|
||||
| facade transform +----------->+ template transform |
|
||||
| | | | |
|
||||
+--------------------+ | +--------------------+
|
||||
|
|
||||
| +--------------------+
|
||||
+----->+ |
|
||||
| style transform |
|
||||
| |
|
||||
+--------------------+
|
||||
```
|
||||
|
||||
Where the facade module looks like this:
|
||||
|
||||
```js
|
||||
// main script
|
||||
import script from '/project/foo.vue?vue&type=script'
|
||||
// template compiled to render function
|
||||
import { render } from '/project/foo.vue?vue&type=template&id=xxxxxx'
|
||||
// css
|
||||
import '/project/foo.vue?vue&type=style&index=0&id=xxxxxx'
|
||||
|
||||
// attach render function to script
|
||||
script.render = render
|
||||
|
||||
// attach additional metadata
|
||||
// some of these should be dev only
|
||||
script.__file = 'example.vue'
|
||||
script.__scopeId = 'xxxxxx'
|
||||
|
||||
// additional tooling-specific HMR handling code
|
||||
// using __VUE_HMR_API__ global
|
||||
|
||||
export default script
|
||||
```
|
||||
|
||||
### High Level Workflow
|
||||
|
||||
1. In facade transform, parse the source into descriptor with the `parse` API and generate the above facade module code based on the descriptor;
|
||||
|
||||
2. In script transform, use `compileScript` to process the script. This handles features like `<script setup>` and CSS variable injection. Alternatively, this can be done directly in the facade module (with the code inlined instead of imported), but it will require rewriting `export default` to a temp variable (a `rewriteDefault` convenience API is provided for this purpose) so additional options can be attached to the exported object.
|
||||
|
||||
3. In template transform, use `compileTemplate` to compile the raw template into render function code.
|
||||
|
||||
4. In style transform, use `compileStyle` to compile raw CSS to handle `<style scoped>`, `<style module>` and CSS variable injection.
|
||||
|
||||
Options needed for these APIs can be passed via the query string.
|
||||
|
||||
For detailed API references and options, check out the source type definitions. For actual usage of these APIs, check out [@vitejs/plugin-vue](https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue) or [vue-loader](https://github.com/vuejs/vue-loader/tree/next).
|
||||
+25580
File diff suppressed because it is too large.
Load diff
+487
@@ -0,0 +1,487 @@
|
||||
import * as _babel_types from '@babel/types';
|
||||
import { Statement, Expression, TSType, Node, Program, CallExpression, ObjectPattern, TSModuleDeclaration, TSPropertySignature, TSMethodSignature, TSCallSignatureDeclaration, TSFunctionType } from '@babel/types';
|
||||
import { RootNode, CompilerOptions, CodegenResult, ParserOptions, RawSourceMap, CompilerError, SourceLocation, BindingMetadata as BindingMetadata$1 } from '@vue/compiler-core';
|
||||
export { BindingMetadata, CompilerError, CompilerOptions, extractIdentifiers, generateCodeFrame, isInDestructureAssignment, isStaticProperty, walkIdentifiers } from '@vue/compiler-core';
|
||||
import { ParserPlugin } from '@babel/parser';
|
||||
export { parse as babelParse } from '@babel/parser';
|
||||
import { Result, LazyResult } from 'postcss';
|
||||
import MagicString from 'magic-string';
|
||||
export { default as MagicString } from 'magic-string';
|
||||
import TS from 'typescript';
|
||||
|
||||
export interface AssetURLTagConfig {
|
||||
[name: string]: string[];
|
||||
}
|
||||
export interface AssetURLOptions {
|
||||
/**
|
||||
* If base is provided, instead of transforming relative asset urls into
|
||||
* imports, they will be directly rewritten to absolute urls.
|
||||
*/
|
||||
base?: string | null;
|
||||
/**
|
||||
* If true, also processes absolute urls.
|
||||
*/
|
||||
includeAbsolute?: boolean;
|
||||
tags?: AssetURLTagConfig;
|
||||
}
|
||||
|
||||
export interface TemplateCompiler {
|
||||
compile(source: string | RootNode, options: CompilerOptions): CodegenResult;
|
||||
parse(template: string, options: ParserOptions): RootNode;
|
||||
}
|
||||
export interface SFCTemplateCompileResults {
|
||||
code: string;
|
||||
ast?: RootNode;
|
||||
preamble?: string;
|
||||
source: string;
|
||||
tips: string[];
|
||||
errors: (string | CompilerError)[];
|
||||
map?: RawSourceMap;
|
||||
}
|
||||
export interface SFCTemplateCompileOptions {
|
||||
source: string;
|
||||
ast?: RootNode;
|
||||
filename: string;
|
||||
id: string;
|
||||
scoped?: boolean;
|
||||
slotted?: boolean;
|
||||
isProd?: boolean;
|
||||
ssr?: boolean;
|
||||
ssrCssVars?: string[];
|
||||
inMap?: RawSourceMap;
|
||||
compiler?: TemplateCompiler;
|
||||
compilerOptions?: CompilerOptions;
|
||||
preprocessLang?: string;
|
||||
preprocessOptions?: any;
|
||||
/**
|
||||
* In some cases, compiler-sfc may not be inside the project root (e.g. when
|
||||
* linked or globally installed). In such cases a custom `require` can be
|
||||
* passed to correctly resolve the preprocessors.
|
||||
*/
|
||||
preprocessCustomRequire?: (id: string) => any;
|
||||
/**
|
||||
* Configure what tags/attributes to transform into asset url imports,
|
||||
* or disable the transform altogether with `false`.
|
||||
*/
|
||||
transformAssetUrls?: AssetURLOptions | AssetURLTagConfig | boolean;
|
||||
}
|
||||
export declare function compileTemplate(options: SFCTemplateCompileOptions): SFCTemplateCompileResults;
|
||||
|
||||
export interface SFCScriptCompileOptions {
|
||||
/**
|
||||
* Scope ID for prefixing injected CSS variables.
|
||||
* This must be consistent with the `id` passed to `compileStyle`.
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* Production mode. Used to determine whether to generate hashed CSS variables
|
||||
*/
|
||||
isProd?: boolean;
|
||||
/**
|
||||
* Enable/disable source map. Defaults to true.
|
||||
*/
|
||||
sourceMap?: boolean;
|
||||
/**
|
||||
* https://babeljs.io/docs/en/babel-parser#plugins
|
||||
*/
|
||||
babelParserPlugins?: ParserPlugin[];
|
||||
/**
|
||||
* A list of files to parse for global types to be made available for type
|
||||
* resolving in SFC macros. The list must be fully resolved file system paths.
|
||||
*/
|
||||
globalTypeFiles?: string[];
|
||||
/**
|
||||
* Compile the template and inline the resulting render function
|
||||
* directly inside setup().
|
||||
* - Only affects `<script setup>`
|
||||
* - This should only be used in production because it prevents the template
|
||||
* from being hot-reloaded separately from component state.
|
||||
*/
|
||||
inlineTemplate?: boolean;
|
||||
/**
|
||||
* Generate the final component as a variable instead of default export.
|
||||
* This is useful in e.g. @vitejs/plugin-vue where the script needs to be
|
||||
* placed inside the main module.
|
||||
*/
|
||||
genDefaultAs?: string;
|
||||
/**
|
||||
* Options for template compilation when inlining. Note these are options that
|
||||
* would normally be passed to `compiler-sfc`'s own `compileTemplate()`, not
|
||||
* options passed to `compiler-dom`.
|
||||
*/
|
||||
templateOptions?: Partial<SFCTemplateCompileOptions>;
|
||||
/**
|
||||
* Hoist <script setup> static constants.
|
||||
* - Only enables when one `<script setup>` exists.
|
||||
* @default true
|
||||
*/
|
||||
hoistStatic?: boolean;
|
||||
/**
|
||||
* Set to `false` to disable reactive destructure for `defineProps` (pre-3.5
|
||||
* behavior), or set to `'error'` to throw hard error on props destructures.
|
||||
* @default true
|
||||
*/
|
||||
propsDestructure?: boolean | 'error';
|
||||
/**
|
||||
* File system access methods to be used when resolving types
|
||||
* imported in SFC macros. Defaults to ts.sys in Node.js, can be overwritten
|
||||
* to use a virtual file system for use in browsers (e.g. in REPLs)
|
||||
*/
|
||||
fs?: {
|
||||
fileExists(file: string): boolean;
|
||||
readFile(file: string): string | undefined;
|
||||
realpath?(file: string): string;
|
||||
};
|
||||
/**
|
||||
* Transform Vue SFCs into custom elements.
|
||||
*/
|
||||
customElement?: boolean | ((filename: string) => boolean);
|
||||
}
|
||||
interface ImportBinding {
|
||||
isType: boolean;
|
||||
imported: string;
|
||||
local: string;
|
||||
source: string;
|
||||
isFromSetup: boolean;
|
||||
isUsedInTemplate: boolean;
|
||||
}
|
||||
/**
|
||||
* Compile `<script setup>`
|
||||
* It requires the whole SFC descriptor because we need to handle and merge
|
||||
* normal `<script>` + `<script setup>` if both are present.
|
||||
*/
|
||||
export declare function compileScript(sfc: SFCDescriptor, options: SFCScriptCompileOptions): SFCScriptBlock;
|
||||
|
||||
export interface SFCParseOptions {
|
||||
filename?: string;
|
||||
sourceMap?: boolean;
|
||||
sourceRoot?: string;
|
||||
pad?: boolean | 'line' | 'space';
|
||||
ignoreEmpty?: boolean;
|
||||
compiler?: TemplateCompiler;
|
||||
templateParseOptions?: ParserOptions;
|
||||
}
|
||||
export interface SFCBlock {
|
||||
type: string;
|
||||
content: string;
|
||||
attrs: Record<string, string | true>;
|
||||
loc: SourceLocation;
|
||||
map?: RawSourceMap;
|
||||
lang?: string;
|
||||
src?: string;
|
||||
}
|
||||
export interface SFCTemplateBlock extends SFCBlock {
|
||||
type: 'template';
|
||||
ast?: RootNode;
|
||||
}
|
||||
export interface SFCScriptBlock extends SFCBlock {
|
||||
type: 'script';
|
||||
setup?: string | boolean;
|
||||
bindings?: BindingMetadata$1;
|
||||
imports?: Record<string, ImportBinding>;
|
||||
scriptAst?: _babel_types.Statement[];
|
||||
scriptSetupAst?: _babel_types.Statement[];
|
||||
warnings?: string[];
|
||||
/**
|
||||
* Fully resolved dependency file paths (unix slashes) with imported types
|
||||
* used in macros, used for HMR cache busting in @vitejs/plugin-vue and
|
||||
* vue-loader.
|
||||
*/
|
||||
deps?: string[];
|
||||
}
|
||||
export interface SFCStyleBlock extends SFCBlock {
|
||||
type: 'style';
|
||||
scoped?: boolean;
|
||||
module?: string | boolean;
|
||||
}
|
||||
export interface SFCDescriptor {
|
||||
filename: string;
|
||||
source: string;
|
||||
template: SFCTemplateBlock | null;
|
||||
script: SFCScriptBlock | null;
|
||||
scriptSetup: SFCScriptBlock | null;
|
||||
styles: SFCStyleBlock[];
|
||||
customBlocks: SFCBlock[];
|
||||
cssVars: string[];
|
||||
/**
|
||||
* whether the SFC uses :slotted() modifier.
|
||||
* this is used as a compiler optimization hint.
|
||||
*/
|
||||
slotted: boolean;
|
||||
/**
|
||||
* compare with an existing descriptor to determine whether HMR should perform
|
||||
* a reload vs. re-render.
|
||||
*
|
||||
* Note: this comparison assumes the prev/next script are already identical,
|
||||
* and only checks the special case where <script setup lang="ts"> unused import
|
||||
* pruning result changes due to template changes.
|
||||
*/
|
||||
shouldForceReload: (prevImports: Record<string, ImportBinding>) => boolean;
|
||||
}
|
||||
export interface SFCParseResult {
|
||||
descriptor: SFCDescriptor;
|
||||
errors: (CompilerError | SyntaxError)[];
|
||||
}
|
||||
export declare function parse(source: string, options?: SFCParseOptions): SFCParseResult;
|
||||
|
||||
type PreprocessLang = 'less' | 'sass' | 'scss' | 'styl' | 'stylus';
|
||||
|
||||
export interface SFCStyleCompileOptions {
|
||||
source: string;
|
||||
filename: string;
|
||||
id: string;
|
||||
scoped?: boolean;
|
||||
trim?: boolean;
|
||||
isProd?: boolean;
|
||||
inMap?: RawSourceMap;
|
||||
preprocessLang?: PreprocessLang;
|
||||
preprocessOptions?: any;
|
||||
preprocessCustomRequire?: (id: string) => any;
|
||||
postcssOptions?: any;
|
||||
postcssPlugins?: any[];
|
||||
/**
|
||||
* @deprecated use `inMap` instead.
|
||||
*/
|
||||
map?: RawSourceMap;
|
||||
}
|
||||
/**
|
||||
* Aligns with postcss-modules
|
||||
* https://github.com/css-modules/postcss-modules
|
||||
*/
|
||||
interface CSSModulesOptions {
|
||||
scopeBehaviour?: 'global' | 'local';
|
||||
generateScopedName?: string | ((name: string, filename: string, css: string) => string);
|
||||
hashPrefix?: string;
|
||||
localsConvention?: 'camelCase' | 'camelCaseOnly' | 'dashes' | 'dashesOnly';
|
||||
exportGlobals?: boolean;
|
||||
globalModulePaths?: RegExp[];
|
||||
}
|
||||
export interface SFCAsyncStyleCompileOptions extends SFCStyleCompileOptions {
|
||||
isAsync?: boolean;
|
||||
modules?: boolean;
|
||||
modulesOptions?: CSSModulesOptions;
|
||||
}
|
||||
export interface SFCStyleCompileResults {
|
||||
code: string;
|
||||
map: RawSourceMap | undefined;
|
||||
rawResult: Result | LazyResult | undefined;
|
||||
errors: Error[];
|
||||
modules?: Record<string, string>;
|
||||
dependencies: Set<string>;
|
||||
}
|
||||
export declare function compileStyle(options: SFCStyleCompileOptions): SFCStyleCompileResults;
|
||||
export declare function compileStyleAsync(options: SFCAsyncStyleCompileOptions): Promise<SFCStyleCompileResults>;
|
||||
|
||||
export declare function rewriteDefault(input: string, as: string, parserPlugins?: ParserPlugin[]): string;
|
||||
/**
|
||||
* Utility for rewriting `export default` in a script block into a variable
|
||||
* declaration so that we can inject things into it
|
||||
*/
|
||||
export declare function rewriteDefaultAST(ast: Statement[], s: MagicString, as: string): void;
|
||||
|
||||
type PropsDestructureBindings = Record<string, // public prop key
|
||||
{
|
||||
local: string;
|
||||
default?: Expression;
|
||||
}>;
|
||||
export declare function extractRuntimeProps(ctx: TypeResolveContext): string | undefined;
|
||||
|
||||
interface ModelDecl {
|
||||
type: TSType | undefined;
|
||||
options: string | undefined;
|
||||
identifier: string | undefined;
|
||||
runtimeOptionNodes: Node[];
|
||||
}
|
||||
|
||||
declare enum BindingTypes {
|
||||
/**
|
||||
* returned from data()
|
||||
*/
|
||||
DATA = "data",
|
||||
/**
|
||||
* declared as a prop
|
||||
*/
|
||||
PROPS = "props",
|
||||
/**
|
||||
* a local alias of a `<script setup>` destructured prop.
|
||||
* the original is stored in __propsAliases of the bindingMetadata object.
|
||||
*/
|
||||
PROPS_ALIASED = "props-aliased",
|
||||
/**
|
||||
* a let binding (may or may not be a ref)
|
||||
*/
|
||||
SETUP_LET = "setup-let",
|
||||
/**
|
||||
* a const binding that can never be a ref.
|
||||
* these bindings don't need `unref()` calls when processed in inlined
|
||||
* template expressions.
|
||||
*/
|
||||
SETUP_CONST = "setup-const",
|
||||
/**
|
||||
* a const binding that does not need `unref()`, but may be mutated.
|
||||
*/
|
||||
SETUP_REACTIVE_CONST = "setup-reactive-const",
|
||||
/**
|
||||
* a const binding that may be a ref.
|
||||
*/
|
||||
SETUP_MAYBE_REF = "setup-maybe-ref",
|
||||
/**
|
||||
* bindings that are guaranteed to be refs
|
||||
*/
|
||||
SETUP_REF = "setup-ref",
|
||||
/**
|
||||
* declared by other options, e.g. computed, inject
|
||||
*/
|
||||
OPTIONS = "options",
|
||||
/**
|
||||
* a literal constant, e.g. 'foo', 1, true
|
||||
*/
|
||||
LITERAL_CONST = "literal-const"
|
||||
}
|
||||
type BindingMetadata = {
|
||||
[key: string]: BindingTypes | undefined;
|
||||
} & {
|
||||
__isScriptSetup?: boolean;
|
||||
__propsAliases?: Record<string, string>;
|
||||
};
|
||||
|
||||
export declare class ScriptCompileContext {
|
||||
descriptor: SFCDescriptor;
|
||||
options: Partial<SFCScriptCompileOptions>;
|
||||
isJS: boolean;
|
||||
isTS: boolean;
|
||||
isCE: boolean;
|
||||
scriptAst: Program | null;
|
||||
scriptSetupAst: Program | null;
|
||||
source: string;
|
||||
filename: string;
|
||||
s: MagicString;
|
||||
startOffset: number | undefined;
|
||||
endOffset: number | undefined;
|
||||
scope?: TypeScope;
|
||||
globalScopes?: TypeScope[];
|
||||
userImports: Record<string, ImportBinding>;
|
||||
hasDefinePropsCall: boolean;
|
||||
hasDefineEmitCall: boolean;
|
||||
hasDefineExposeCall: boolean;
|
||||
hasDefaultExportName: boolean;
|
||||
hasDefaultExportRender: boolean;
|
||||
hasDefineOptionsCall: boolean;
|
||||
hasDefineSlotsCall: boolean;
|
||||
hasDefineModelCall: boolean;
|
||||
propsCall: CallExpression | undefined;
|
||||
propsDecl: Node | undefined;
|
||||
propsRuntimeDecl: Node | undefined;
|
||||
propsTypeDecl: Node | undefined;
|
||||
propsDestructureDecl: ObjectPattern | undefined;
|
||||
propsDestructuredBindings: PropsDestructureBindings;
|
||||
propsDestructureRestId: string | undefined;
|
||||
propsRuntimeDefaults: Node | undefined;
|
||||
emitsRuntimeDecl: Node | undefined;
|
||||
emitsTypeDecl: Node | undefined;
|
||||
emitDecl: Node | undefined;
|
||||
modelDecls: Record<string, ModelDecl>;
|
||||
optionsRuntimeDecl: Node | undefined;
|
||||
bindingMetadata: BindingMetadata;
|
||||
helperImports: Set<string>;
|
||||
helper(key: string): string;
|
||||
/**
|
||||
* to be exposed on compiled script block for HMR cache busting
|
||||
*/
|
||||
deps?: Set<string>;
|
||||
/**
|
||||
* cache for resolved fs
|
||||
*/
|
||||
fs?: NonNullable<SFCScriptCompileOptions['fs']>;
|
||||
constructor(descriptor: SFCDescriptor, options: Partial<SFCScriptCompileOptions>);
|
||||
getString(node: Node, scriptSetup?: boolean): string;
|
||||
warn(msg: string, node: Node, scope?: TypeScope): void;
|
||||
error(msg: string, node: Node, scope?: TypeScope): never;
|
||||
}
|
||||
|
||||
export type SimpleTypeResolveOptions = Partial<Pick<SFCScriptCompileOptions, 'globalTypeFiles' | 'fs' | 'babelParserPlugins' | 'isProd'>>;
|
||||
/**
|
||||
* TypeResolveContext is compatible with ScriptCompileContext
|
||||
* but also allows a simpler version of it with minimal required properties
|
||||
* when resolveType needs to be used in a non-SFC context, e.g. in a babel
|
||||
* plugin. The simplest context can be just:
|
||||
* ```ts
|
||||
* const ctx: SimpleTypeResolveContext = {
|
||||
* filename: '...',
|
||||
* source: '...',
|
||||
* options: {},
|
||||
* error() {},
|
||||
* ast: []
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
export type SimpleTypeResolveContext = Pick<ScriptCompileContext, 'source' | 'filename' | 'error' | 'warn' | 'helper' | 'getString' | 'propsTypeDecl' | 'propsRuntimeDefaults' | 'propsDestructuredBindings' | 'emitsTypeDecl' | 'isCE'> & Partial<Pick<ScriptCompileContext, 'scope' | 'globalScopes' | 'deps' | 'fs'>> & {
|
||||
ast: Statement[];
|
||||
options: SimpleTypeResolveOptions;
|
||||
};
|
||||
export type TypeResolveContext = (ScriptCompileContext | SimpleTypeResolveContext) & {
|
||||
silentOnExtendsFailure?: boolean;
|
||||
};
|
||||
type Import = Pick<ImportBinding, 'source' | 'imported'>;
|
||||
interface WithScope {
|
||||
_ownerScope: TypeScope;
|
||||
}
|
||||
type ScopeTypeNode = Node & WithScope & {
|
||||
_ns?: TSModuleDeclaration & WithScope;
|
||||
};
|
||||
declare class TypeScope {
|
||||
filename: string;
|
||||
source: string;
|
||||
offset: number;
|
||||
imports: Record<string, Import>;
|
||||
types: Record<string, ScopeTypeNode>;
|
||||
declares: Record<string, ScopeTypeNode>;
|
||||
constructor(filename: string, source: string, offset?: number, imports?: Record<string, Import>, types?: Record<string, ScopeTypeNode>, declares?: Record<string, ScopeTypeNode>);
|
||||
isGenericScope: boolean;
|
||||
resolvedImportSources: Record<string, string>;
|
||||
exportedTypes: Record<string, ScopeTypeNode>;
|
||||
exportedDeclares: Record<string, ScopeTypeNode>;
|
||||
}
|
||||
interface MaybeWithScope {
|
||||
_ownerScope?: TypeScope;
|
||||
}
|
||||
interface ResolvedElements {
|
||||
props: Record<string, (TSPropertySignature | TSMethodSignature) & {
|
||||
_ownerScope: TypeScope;
|
||||
}>;
|
||||
calls?: (TSCallSignatureDeclaration | TSFunctionType)[];
|
||||
}
|
||||
/**
|
||||
* Resolve arbitrary type node to a list of type elements that can be then
|
||||
* mapped to runtime props or emits.
|
||||
*/
|
||||
export declare function resolveTypeElements(ctx: TypeResolveContext, node: Node & MaybeWithScope & {
|
||||
_resolvedElements?: ResolvedElements;
|
||||
}, scope?: TypeScope, typeParameters?: Record<string, Node>): ResolvedElements;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
export declare function registerTS(_loadTS: () => typeof TS): void;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
export declare function invalidateTypeCache(filename: string): void;
|
||||
export declare function inferRuntimeType(ctx: TypeResolveContext, node: Node & MaybeWithScope, scope?: TypeScope, isKeyOf?: boolean, typeParameters?: Record<string, Node>): string[];
|
||||
|
||||
export declare function extractRuntimeEmits(ctx: TypeResolveContext): Set<string>;
|
||||
|
||||
export declare const version: string;
|
||||
|
||||
export declare const parseCache: Map<string, SFCParseResult>;
|
||||
export declare const errorMessages: Record<number, string>;
|
||||
|
||||
export declare const walk: any;
|
||||
|
||||
/**
|
||||
* @deprecated this is preserved to avoid breaking vite-plugin-vue < 5.0
|
||||
* with reactivityTransform: true. The desired behavior should be silently
|
||||
* ignoring the option instead of breaking.
|
||||
*/
|
||||
export declare const shouldTransformRef: () => boolean;
|
||||
|
||||
|
||||
+50795
File diff suppressed because it is too large.
Load diff
+67
@@ -0,0 +1,67 @@
|
||||
{
|
||||
"name": "@vue/compiler-sfc",
|
||||
"version": "3.5.30",
|
||||
"description": "@vue/compiler-sfc",
|
||||
"main": "dist/compiler-sfc.cjs.js",
|
||||
"module": "dist/compiler-sfc.esm-browser.js",
|
||||
"types": "dist/compiler-sfc.d.ts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/compiler-sfc.d.ts",
|
||||
"node": "./dist/compiler-sfc.cjs.js",
|
||||
"module": "./dist/compiler-sfc.esm-browser.js",
|
||||
"import": "./dist/compiler-sfc.esm-browser.js",
|
||||
"require": "./dist/compiler-sfc.cjs.js"
|
||||
},
|
||||
"./*": "./*"
|
||||
},
|
||||
"buildOptions": {
|
||||
"name": "VueCompilerSFC",
|
||||
"formats": [
|
||||
"cjs",
|
||||
"esm-browser"
|
||||
],
|
||||
"prod": false,
|
||||
"enableNonBrowserBranches": true
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/vuejs/core.git",
|
||||
"directory": "packages/compiler-sfc"
|
||||
},
|
||||
"keywords": [
|
||||
"vue"
|
||||
],
|
||||
"author": "Evan You",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/vuejs/core/issues"
|
||||
},
|
||||
"homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-sfc#readme",
|
||||
"dependencies": {
|
||||
"@babel/parser": "^7.29.0",
|
||||
"estree-walker": "^2.0.2",
|
||||
"magic-string": "^0.30.21",
|
||||
"postcss": "^8.5.8",
|
||||
"source-map-js": "^1.2.1",
|
||||
"@vue/compiler-dom": "3.5.30",
|
||||
"@vue/compiler-core": "3.5.30",
|
||||
"@vue/compiler-ssr": "3.5.30",
|
||||
"@vue/shared": "3.5.30"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/types": "^7.29.0",
|
||||
"@vue/consolidate": "^1.0.0",
|
||||
"hash-sum": "^2.0.0",
|
||||
"lru-cache": "10.1.0",
|
||||
"merge-source-map": "^1.1.0",
|
||||
"minimatch": "~10.2.4",
|
||||
"postcss-modules": "^6.0.1",
|
||||
"postcss-selector-parser": "^7.1.1",
|
||||
"pug": "^3.0.3",
|
||||
"sass": "^1.97.3"
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2018-present, Yuxi (Evan) You
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
+1
@@ -0,0 +1 @@
|
||||
# @vue/compiler-ssr
|
||||
+1413
File diff suppressed because it is too large.
Load diff
+4
@@ -0,0 +1,4 @@
|
||||
import { RootNode, CompilerOptions, CodegenResult } from '@vue/compiler-dom';
|
||||
|
||||
export declare function compile(source: string | RootNode, options?: CompilerOptions): CodegenResult;
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "@vue/compiler-ssr",
|
||||
"version": "3.5.30",
|
||||
"description": "@vue/compiler-ssr",
|
||||
"main": "dist/compiler-ssr.cjs.js",
|
||||
"types": "dist/compiler-ssr.d.ts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"buildOptions": {
|
||||
"prod": false,
|
||||
"formats": [
|
||||
"cjs"
|
||||
]
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/vuejs/core.git",
|
||||
"directory": "packages/compiler-ssr"
|
||||
},
|
||||
"keywords": [
|
||||
"vue"
|
||||
],
|
||||
"author": "Evan You",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/vuejs/core/issues"
|
||||
},
|
||||
"homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-ssr#readme",
|
||||
"dependencies": {
|
||||
"@vue/compiler-dom": "3.5.30",
|
||||
"@vue/shared": "3.5.30"
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 webfansplz
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
# @vue/devtools-api
|
||||
|
||||
> Plugins API for easier DevTools integrations.
|
||||
|
||||
## Getting Started
|
||||
|
||||
Please follow the documentation at [devtools.vuejs.org](https://devtools.vuejs.org/plugins/api).
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
||||
let _vue_devtools_kit = require("@vue/devtools-kit");
|
||||
Object.defineProperty(exports, "addCustomCommand", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return _vue_devtools_kit.addCustomCommand;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "addCustomTab", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return _vue_devtools_kit.addCustomTab;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "onDevToolsClientConnected", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return _vue_devtools_kit.onDevToolsClientConnected;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "onDevToolsConnected", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return _vue_devtools_kit.onDevToolsConnected;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "removeCustomCommand", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return _vue_devtools_kit.removeCustomCommand;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "setupDevToolsPlugin", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return _vue_devtools_kit.setupDevToolsPlugin;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "setupDevtoolsPlugin", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return _vue_devtools_kit.setupDevToolsPlugin;
|
||||
}
|
||||
});
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
import { CustomCommand, CustomTab, addCustomCommand, addCustomTab, onDevToolsClientConnected, onDevToolsConnected, removeCustomCommand, setupDevToolsPlugin, setupDevToolsPlugin as setupDevtoolsPlugin } from "@vue/devtools-kit";
|
||||
export { type CustomCommand, type CustomTab, addCustomCommand, addCustomTab, onDevToolsClientConnected, onDevToolsConnected, removeCustomCommand, setupDevToolsPlugin, setupDevtoolsPlugin };
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
import { CustomCommand, CustomTab, addCustomCommand, addCustomTab, onDevToolsClientConnected, onDevToolsConnected, removeCustomCommand, setupDevToolsPlugin, setupDevToolsPlugin as setupDevtoolsPlugin } from "@vue/devtools-kit";
|
||||
export { type CustomCommand, type CustomTab, addCustomCommand, addCustomTab, onDevToolsClientConnected, onDevToolsConnected, removeCustomCommand, setupDevToolsPlugin, setupDevtoolsPlugin };
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
import { addCustomCommand, addCustomTab, onDevToolsClientConnected, onDevToolsConnected, removeCustomCommand, setupDevToolsPlugin, setupDevToolsPlugin as setupDevtoolsPlugin } from "@vue/devtools-kit";
|
||||
export { addCustomCommand, addCustomTab, onDevToolsClientConnected, onDevToolsConnected, removeCustomCommand, setupDevToolsPlugin, setupDevtoolsPlugin };
|
||||
+3914
File diff suppressed because it is too large.
Load diff
+3924
File diff suppressed because it is too large.
Load diff
+34
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "@vue/devtools-api",
|
||||
"type": "module",
|
||||
"version": "8.1.0",
|
||||
"author": "webfansplz",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"directory": "packages/devtools-api",
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/vuejs/devtools.git"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/index.js",
|
||||
"require": "./dist/index.cjs"
|
||||
}
|
||||
},
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
"unpkg": "dist/vue-devtools-api.global.js",
|
||||
"jsdelivr": "dist/vue-devtools-api.global.js",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"dependencies": {
|
||||
"@vue/devtools-kit": "^8.1.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsdown --clean",
|
||||
"prepare:type": "tsdown --dts-only",
|
||||
"stub": "tsdown --watch --onSuccess 'tsdown --dts-only'"
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 webfansplz
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
# @vue/devtools-kit
|
||||
|
||||
> Utility kit for DevTools.
|
||||
+5765
File diff suppressed because it is too large.
Load diff
+23220
File diff suppressed because it is too large.
Load diff
+23220
File diff suppressed because it is too large.
Load diff
+5683
File diff suppressed because it is too large.
Load diff
+20
@@ -0,0 +1,20 @@
|
||||
import type { DevToolsHook, RouterInfo } from './src/types'
|
||||
|
||||
/* eslint-disable vars-on-top */
|
||||
declare global {
|
||||
var __VUE_DEVTOOLS_GLOBAL_HOOK__: DevToolsHook
|
||||
var __VUE_DEVTOOLS_NEXT_APP_RECORD_INFO__: {
|
||||
id: number
|
||||
appIds: Set<string>
|
||||
}
|
||||
var __VUE_DEVTOOLS_ROUTER_INFO__: RouterInfo
|
||||
var __VUE_DEVTOOLS_ENV__: {
|
||||
vitePluginDetected: boolean
|
||||
}
|
||||
var __VUE_DEVTOOLS_COMPONENT_INSPECTOR_ENABLED__: boolean
|
||||
var __VUE_DEVTOOLS_VITE_PLUGIN_DETECTED__: boolean
|
||||
var __VUE_DEVTOOLS_VITE_PLUGIN_CLIENT_URL__: string
|
||||
var __VUE_DEVTOOLS_BROWSER_EXTENSION_DETECTED__: boolean
|
||||
}
|
||||
|
||||
export { }
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"name": "@vue/devtools-kit",
|
||||
"type": "module",
|
||||
"version": "8.1.0",
|
||||
"author": "webfansplz",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"directory": "packages/devtools-kit",
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/vuejs/devtools.git"
|
||||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/index.js",
|
||||
"require": "./dist/index.cjs"
|
||||
}
|
||||
},
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
"types": "./types.d.ts",
|
||||
"files": [
|
||||
"**.d.ts",
|
||||
"dist"
|
||||
],
|
||||
"dependencies": {
|
||||
"birpc": "^2.6.1",
|
||||
"hookable": "^5.5.3",
|
||||
"perfect-debounce": "^2.0.0",
|
||||
"@vue/devtools-shared": "^8.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/speakingurl": "^13.0.6",
|
||||
"speakingurl": "^14.0.1",
|
||||
"superjson": "^2.2.2",
|
||||
"vue": "^3.5.22",
|
||||
"vue-router": "^4.6.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsdown --clean",
|
||||
"prepare:type": "tsdown --dts-only",
|
||||
"stub": "tsdown --watch --onSuccess 'tsdown --dts-only'"
|
||||
}
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
/// <reference path="./global.d.ts" />
|
||||
export * from './dist/index'
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 webfansplz
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
# @vue/devtools-shared
|
||||
|
||||
> Internal utility types shared across @vue/devtools packages.
|
||||
+265
@@ -0,0 +1,265 @@
|
||||
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
||||
//#region \0rolldown/runtime.js
|
||||
var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
||||
key = keys[i];
|
||||
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
||||
get: ((k) => from[k]).bind(null, key),
|
||||
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
||||
});
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
||||
value: mod,
|
||||
enumerable: true
|
||||
}) : target, mod));
|
||||
//#endregion
|
||||
//#region src/constants.ts
|
||||
const VIEW_MODE_STORAGE_KEY = "__vue-devtools-view-mode__";
|
||||
const VITE_PLUGIN_DETECTED_STORAGE_KEY = "__vue-devtools-vite-plugin-detected__";
|
||||
const VITE_PLUGIN_CLIENT_URL_STORAGE_KEY = "__vue-devtools-vite-plugin-client-url__";
|
||||
const BROADCAST_CHANNEL_NAME = "__vue-devtools-broadcast-channel__";
|
||||
//#endregion
|
||||
//#region src/env.ts
|
||||
const isBrowser = typeof navigator !== "undefined";
|
||||
const target = typeof window !== "undefined" ? window : typeof globalThis !== "undefined" ? globalThis : typeof global !== "undefined" ? global : {};
|
||||
const isInChromePanel = typeof target.chrome !== "undefined" && !!target.chrome.devtools;
|
||||
const isInIframe = isBrowser && target.self !== target.top;
|
||||
const isInElectron = typeof navigator !== "undefined" && navigator.userAgent?.toLowerCase().includes("electron");
|
||||
const isNuxtApp = typeof window !== "undefined" && !!window.__NUXT__;
|
||||
const isInSeparateWindow = !isInIframe && !isInChromePanel && !isInElectron;
|
||||
//#endregion
|
||||
//#region src/general.ts
|
||||
var import_rfdc = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
||||
module.exports = rfdc;
|
||||
function copyBuffer(cur) {
|
||||
if (cur instanceof Buffer) return Buffer.from(cur);
|
||||
return new cur.constructor(cur.buffer.slice(), cur.byteOffset, cur.length);
|
||||
}
|
||||
function rfdc(opts) {
|
||||
opts = opts || {};
|
||||
if (opts.circles) return rfdcCircles(opts);
|
||||
const constructorHandlers = /* @__PURE__ */ new Map();
|
||||
constructorHandlers.set(Date, (o) => new Date(o));
|
||||
constructorHandlers.set(Map, (o, fn) => new Map(cloneArray(Array.from(o), fn)));
|
||||
constructorHandlers.set(Set, (o, fn) => new Set(cloneArray(Array.from(o), fn)));
|
||||
if (opts.constructorHandlers) for (const handler of opts.constructorHandlers) constructorHandlers.set(handler[0], handler[1]);
|
||||
let handler = null;
|
||||
return opts.proto ? cloneProto : clone;
|
||||
function cloneArray(a, fn) {
|
||||
const keys = Object.keys(a);
|
||||
const a2 = new Array(keys.length);
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
const k = keys[i];
|
||||
const cur = a[k];
|
||||
if (typeof cur !== "object" || cur === null) a2[k] = cur;
|
||||
else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) a2[k] = handler(cur, fn);
|
||||
else if (ArrayBuffer.isView(cur)) a2[k] = copyBuffer(cur);
|
||||
else a2[k] = fn(cur);
|
||||
}
|
||||
return a2;
|
||||
}
|
||||
function clone(o) {
|
||||
if (typeof o !== "object" || o === null) return o;
|
||||
if (Array.isArray(o)) return cloneArray(o, clone);
|
||||
if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) return handler(o, clone);
|
||||
const o2 = {};
|
||||
for (const k in o) {
|
||||
if (Object.hasOwnProperty.call(o, k) === false) continue;
|
||||
const cur = o[k];
|
||||
if (typeof cur !== "object" || cur === null) o2[k] = cur;
|
||||
else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) o2[k] = handler(cur, clone);
|
||||
else if (ArrayBuffer.isView(cur)) o2[k] = copyBuffer(cur);
|
||||
else o2[k] = clone(cur);
|
||||
}
|
||||
return o2;
|
||||
}
|
||||
function cloneProto(o) {
|
||||
if (typeof o !== "object" || o === null) return o;
|
||||
if (Array.isArray(o)) return cloneArray(o, cloneProto);
|
||||
if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) return handler(o, cloneProto);
|
||||
const o2 = {};
|
||||
for (const k in o) {
|
||||
const cur = o[k];
|
||||
if (typeof cur !== "object" || cur === null) o2[k] = cur;
|
||||
else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) o2[k] = handler(cur, cloneProto);
|
||||
else if (ArrayBuffer.isView(cur)) o2[k] = copyBuffer(cur);
|
||||
else o2[k] = cloneProto(cur);
|
||||
}
|
||||
return o2;
|
||||
}
|
||||
}
|
||||
function rfdcCircles(opts) {
|
||||
const refs = [];
|
||||
const refsNew = [];
|
||||
const constructorHandlers = /* @__PURE__ */ new Map();
|
||||
constructorHandlers.set(Date, (o) => new Date(o));
|
||||
constructorHandlers.set(Map, (o, fn) => new Map(cloneArray(Array.from(o), fn)));
|
||||
constructorHandlers.set(Set, (o, fn) => new Set(cloneArray(Array.from(o), fn)));
|
||||
if (opts.constructorHandlers) for (const handler of opts.constructorHandlers) constructorHandlers.set(handler[0], handler[1]);
|
||||
let handler = null;
|
||||
return opts.proto ? cloneProto : clone;
|
||||
function cloneArray(a, fn) {
|
||||
const keys = Object.keys(a);
|
||||
const a2 = new Array(keys.length);
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
const k = keys[i];
|
||||
const cur = a[k];
|
||||
if (typeof cur !== "object" || cur === null) a2[k] = cur;
|
||||
else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) a2[k] = handler(cur, fn);
|
||||
else if (ArrayBuffer.isView(cur)) a2[k] = copyBuffer(cur);
|
||||
else {
|
||||
const index = refs.indexOf(cur);
|
||||
if (index !== -1) a2[k] = refsNew[index];
|
||||
else a2[k] = fn(cur);
|
||||
}
|
||||
}
|
||||
return a2;
|
||||
}
|
||||
function clone(o) {
|
||||
if (typeof o !== "object" || o === null) return o;
|
||||
if (Array.isArray(o)) return cloneArray(o, clone);
|
||||
if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) return handler(o, clone);
|
||||
const o2 = {};
|
||||
refs.push(o);
|
||||
refsNew.push(o2);
|
||||
for (const k in o) {
|
||||
if (Object.hasOwnProperty.call(o, k) === false) continue;
|
||||
const cur = o[k];
|
||||
if (typeof cur !== "object" || cur === null) o2[k] = cur;
|
||||
else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) o2[k] = handler(cur, clone);
|
||||
else if (ArrayBuffer.isView(cur)) o2[k] = copyBuffer(cur);
|
||||
else {
|
||||
const i = refs.indexOf(cur);
|
||||
if (i !== -1) o2[k] = refsNew[i];
|
||||
else o2[k] = clone(cur);
|
||||
}
|
||||
}
|
||||
refs.pop();
|
||||
refsNew.pop();
|
||||
return o2;
|
||||
}
|
||||
function cloneProto(o) {
|
||||
if (typeof o !== "object" || o === null) return o;
|
||||
if (Array.isArray(o)) return cloneArray(o, cloneProto);
|
||||
if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) return handler(o, cloneProto);
|
||||
const o2 = {};
|
||||
refs.push(o);
|
||||
refsNew.push(o2);
|
||||
for (const k in o) {
|
||||
const cur = o[k];
|
||||
if (typeof cur !== "object" || cur === null) o2[k] = cur;
|
||||
else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) o2[k] = handler(cur, cloneProto);
|
||||
else if (ArrayBuffer.isView(cur)) o2[k] = copyBuffer(cur);
|
||||
else {
|
||||
const i = refs.indexOf(cur);
|
||||
if (i !== -1) o2[k] = refsNew[i];
|
||||
else o2[k] = cloneProto(cur);
|
||||
}
|
||||
}
|
||||
refs.pop();
|
||||
refsNew.pop();
|
||||
return o2;
|
||||
}
|
||||
}
|
||||
})))(), 1);
|
||||
function NOOP() {}
|
||||
const isNumeric = (str) => `${+str}` === str;
|
||||
const isMacOS = () => navigator?.platform ? navigator?.platform.toLowerCase().includes("mac") : /Macintosh/.test(navigator.userAgent);
|
||||
const classifyRE = /(?:^|[-_/])(\w)/g;
|
||||
const camelizeRE = /-(\w)/g;
|
||||
const kebabizeRE = /([a-z0-9])([A-Z])/g;
|
||||
function toUpper(_, c) {
|
||||
return c ? c.toUpperCase() : "";
|
||||
}
|
||||
function classify(str) {
|
||||
return str && `${str}`.replace(classifyRE, toUpper);
|
||||
}
|
||||
function camelize(str) {
|
||||
return str && str.replace(camelizeRE, toUpper);
|
||||
}
|
||||
function kebabize(str) {
|
||||
return str && str.replace(kebabizeRE, (_, lowerCaseCharacter, upperCaseLetter) => {
|
||||
return `${lowerCaseCharacter}-${upperCaseLetter}`;
|
||||
}).toLowerCase();
|
||||
}
|
||||
function basename(filename, ext) {
|
||||
let normalizedFilename = filename.replace(/^[a-z]:/i, "").replace(/\\/g, "/");
|
||||
if (normalizedFilename.endsWith(`index${ext}`)) normalizedFilename = normalizedFilename.replace(`/index${ext}`, ext);
|
||||
const lastSlashIndex = normalizedFilename.lastIndexOf("/");
|
||||
const baseNameWithExt = normalizedFilename.substring(lastSlashIndex + 1);
|
||||
if (ext) {
|
||||
const extIndex = baseNameWithExt.lastIndexOf(ext);
|
||||
return baseNameWithExt.substring(0, extIndex);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
function sortByKey(state) {
|
||||
return state && state.slice().sort((a, b) => {
|
||||
if (a.key < b.key) return -1;
|
||||
if (a.key > b.key) return 1;
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
const HTTP_URL_RE = /^https?:\/\//;
|
||||
/**
|
||||
* Check a string is start with `/` or a valid http url
|
||||
*/
|
||||
function isUrlString(str) {
|
||||
return str.startsWith("/") || HTTP_URL_RE.test(str);
|
||||
}
|
||||
/**
|
||||
* @copyright [rfdc](https://github.com/davidmarkclements/rfdc)
|
||||
* @description A really fast deep clone alternative
|
||||
*/
|
||||
const deepClone = (0, import_rfdc.default)({ circles: true });
|
||||
function randomStr() {
|
||||
return Math.random().toString(36).slice(2);
|
||||
}
|
||||
function isObject(value) {
|
||||
return typeof value === "object" && !Array.isArray(value) && value !== null;
|
||||
}
|
||||
function isArray(value) {
|
||||
return Array.isArray(value);
|
||||
}
|
||||
function isSet(value) {
|
||||
return value instanceof Set;
|
||||
}
|
||||
function isMap(value) {
|
||||
return value instanceof Map;
|
||||
}
|
||||
//#endregion
|
||||
exports.BROADCAST_CHANNEL_NAME = BROADCAST_CHANNEL_NAME;
|
||||
exports.NOOP = NOOP;
|
||||
exports.VIEW_MODE_STORAGE_KEY = VIEW_MODE_STORAGE_KEY;
|
||||
exports.VITE_PLUGIN_CLIENT_URL_STORAGE_KEY = VITE_PLUGIN_CLIENT_URL_STORAGE_KEY;
|
||||
exports.VITE_PLUGIN_DETECTED_STORAGE_KEY = VITE_PLUGIN_DETECTED_STORAGE_KEY;
|
||||
exports.basename = basename;
|
||||
exports.camelize = camelize;
|
||||
exports.classify = classify;
|
||||
exports.deepClone = deepClone;
|
||||
exports.isArray = isArray;
|
||||
exports.isBrowser = isBrowser;
|
||||
exports.isInChromePanel = isInChromePanel;
|
||||
exports.isInElectron = isInElectron;
|
||||
exports.isInIframe = isInIframe;
|
||||
exports.isInSeparateWindow = isInSeparateWindow;
|
||||
exports.isMacOS = isMacOS;
|
||||
exports.isMap = isMap;
|
||||
exports.isNumeric = isNumeric;
|
||||
exports.isNuxtApp = isNuxtApp;
|
||||
exports.isObject = isObject;
|
||||
exports.isSet = isSet;
|
||||
exports.isUrlString = isUrlString;
|
||||
exports.kebabize = kebabize;
|
||||
exports.randomStr = randomStr;
|
||||
exports.sortByKey = sortByKey;
|
||||
exports.target = target;
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
//#region src/constants.d.ts
|
||||
declare const VIEW_MODE_STORAGE_KEY = "__vue-devtools-view-mode__";
|
||||
declare const VITE_PLUGIN_DETECTED_STORAGE_KEY = "__vue-devtools-vite-plugin-detected__";
|
||||
declare const VITE_PLUGIN_CLIENT_URL_STORAGE_KEY = "__vue-devtools-vite-plugin-client-url__";
|
||||
declare const BROADCAST_CHANNEL_NAME = "__vue-devtools-broadcast-channel__";
|
||||
//#endregion
|
||||
//#region src/env.d.ts
|
||||
declare const isBrowser: boolean;
|
||||
declare const target: typeof globalThis;
|
||||
declare const isInChromePanel: boolean;
|
||||
declare const isInIframe: boolean;
|
||||
declare const isInElectron: boolean;
|
||||
declare const isNuxtApp: boolean;
|
||||
declare const isInSeparateWindow: boolean;
|
||||
//#endregion
|
||||
//#region src/general.d.ts
|
||||
declare function NOOP(): void;
|
||||
declare const isNumeric: (str: string | number) => boolean;
|
||||
declare const isMacOS: () => boolean;
|
||||
declare function classify(str: string): string;
|
||||
declare function camelize(str: string): string;
|
||||
declare function kebabize(str: string): string;
|
||||
declare function basename(filename: string, ext: string): string;
|
||||
declare function sortByKey(state: unknown[]): Record<"key", number>[];
|
||||
/**
|
||||
* Check a string is start with `/` or a valid http url
|
||||
*/
|
||||
declare function isUrlString(str: string): boolean;
|
||||
/**
|
||||
* @copyright [rfdc](https://github.com/davidmarkclements/rfdc)
|
||||
* @description A really fast deep clone alternative
|
||||
*/
|
||||
declare const deepClone: <T>(input: T) => T;
|
||||
declare function randomStr(): string;
|
||||
declare function isObject<T extends object>(value: any): value is T;
|
||||
declare function isArray<T>(value: any): value is T[];
|
||||
declare function isSet<T>(value: any): value is Set<T>;
|
||||
declare function isMap<K, V>(value: any): value is Map<K, V>;
|
||||
//#endregion
|
||||
export { BROADCAST_CHANNEL_NAME, NOOP, VIEW_MODE_STORAGE_KEY, VITE_PLUGIN_CLIENT_URL_STORAGE_KEY, VITE_PLUGIN_DETECTED_STORAGE_KEY, basename, camelize, classify, deepClone, isArray, isBrowser, isInChromePanel, isInElectron, isInIframe, isInSeparateWindow, isMacOS, isMap, isNumeric, isNuxtApp, isObject, isSet, isUrlString, kebabize, randomStr, sortByKey, target };
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
//#region src/constants.d.ts
|
||||
declare const VIEW_MODE_STORAGE_KEY = "__vue-devtools-view-mode__";
|
||||
declare const VITE_PLUGIN_DETECTED_STORAGE_KEY = "__vue-devtools-vite-plugin-detected__";
|
||||
declare const VITE_PLUGIN_CLIENT_URL_STORAGE_KEY = "__vue-devtools-vite-plugin-client-url__";
|
||||
declare const BROADCAST_CHANNEL_NAME = "__vue-devtools-broadcast-channel__";
|
||||
//#endregion
|
||||
//#region src/env.d.ts
|
||||
declare const isBrowser: boolean;
|
||||
declare const target: typeof globalThis;
|
||||
declare const isInChromePanel: boolean;
|
||||
declare const isInIframe: boolean;
|
||||
declare const isInElectron: boolean;
|
||||
declare const isNuxtApp: boolean;
|
||||
declare const isInSeparateWindow: boolean;
|
||||
//#endregion
|
||||
//#region src/general.d.ts
|
||||
declare function NOOP(): void;
|
||||
declare const isNumeric: (str: string | number) => boolean;
|
||||
declare const isMacOS: () => boolean;
|
||||
declare function classify(str: string): string;
|
||||
declare function camelize(str: string): string;
|
||||
declare function kebabize(str: string): string;
|
||||
declare function basename(filename: string, ext: string): string;
|
||||
declare function sortByKey(state: unknown[]): Record<"key", number>[];
|
||||
/**
|
||||
* Check a string is start with `/` or a valid http url
|
||||
*/
|
||||
declare function isUrlString(str: string): boolean;
|
||||
/**
|
||||
* @copyright [rfdc](https://github.com/davidmarkclements/rfdc)
|
||||
* @description A really fast deep clone alternative
|
||||
*/
|
||||
declare const deepClone: <T>(input: T) => T;
|
||||
declare function randomStr(): string;
|
||||
declare function isObject<T extends object>(value: any): value is T;
|
||||
declare function isArray<T>(value: any): value is T[];
|
||||
declare function isSet<T>(value: any): value is Set<T>;
|
||||
declare function isMap<K, V>(value: any): value is Map<K, V>;
|
||||
//#endregion
|
||||
export { BROADCAST_CHANNEL_NAME, NOOP, VIEW_MODE_STORAGE_KEY, VITE_PLUGIN_CLIENT_URL_STORAGE_KEY, VITE_PLUGIN_DETECTED_STORAGE_KEY, basename, camelize, classify, deepClone, isArray, isBrowser, isInChromePanel, isInElectron, isInIframe, isInSeparateWindow, isMacOS, isMap, isNumeric, isNuxtApp, isObject, isSet, isUrlString, kebabize, randomStr, sortByKey, target };
|
||||
+239
@@ -0,0 +1,239 @@
|
||||
//#region \0rolldown/runtime.js
|
||||
var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
||||
key = keys[i];
|
||||
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
||||
get: ((k) => from[k]).bind(null, key),
|
||||
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
||||
});
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
||||
value: mod,
|
||||
enumerable: true
|
||||
}) : target, mod));
|
||||
//#endregion
|
||||
//#region src/constants.ts
|
||||
const VIEW_MODE_STORAGE_KEY = "__vue-devtools-view-mode__";
|
||||
const VITE_PLUGIN_DETECTED_STORAGE_KEY = "__vue-devtools-vite-plugin-detected__";
|
||||
const VITE_PLUGIN_CLIENT_URL_STORAGE_KEY = "__vue-devtools-vite-plugin-client-url__";
|
||||
const BROADCAST_CHANNEL_NAME = "__vue-devtools-broadcast-channel__";
|
||||
//#endregion
|
||||
//#region src/env.ts
|
||||
const isBrowser = typeof navigator !== "undefined";
|
||||
const target = typeof window !== "undefined" ? window : typeof globalThis !== "undefined" ? globalThis : typeof global !== "undefined" ? global : {};
|
||||
const isInChromePanel = typeof target.chrome !== "undefined" && !!target.chrome.devtools;
|
||||
const isInIframe = isBrowser && target.self !== target.top;
|
||||
const isInElectron = typeof navigator !== "undefined" && navigator.userAgent?.toLowerCase().includes("electron");
|
||||
const isNuxtApp = typeof window !== "undefined" && !!window.__NUXT__;
|
||||
const isInSeparateWindow = !isInIframe && !isInChromePanel && !isInElectron;
|
||||
//#endregion
|
||||
//#region src/general.ts
|
||||
var import_rfdc = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
||||
module.exports = rfdc;
|
||||
function copyBuffer(cur) {
|
||||
if (cur instanceof Buffer) return Buffer.from(cur);
|
||||
return new cur.constructor(cur.buffer.slice(), cur.byteOffset, cur.length);
|
||||
}
|
||||
function rfdc(opts) {
|
||||
opts = opts || {};
|
||||
if (opts.circles) return rfdcCircles(opts);
|
||||
const constructorHandlers = /* @__PURE__ */ new Map();
|
||||
constructorHandlers.set(Date, (o) => new Date(o));
|
||||
constructorHandlers.set(Map, (o, fn) => new Map(cloneArray(Array.from(o), fn)));
|
||||
constructorHandlers.set(Set, (o, fn) => new Set(cloneArray(Array.from(o), fn)));
|
||||
if (opts.constructorHandlers) for (const handler of opts.constructorHandlers) constructorHandlers.set(handler[0], handler[1]);
|
||||
let handler = null;
|
||||
return opts.proto ? cloneProto : clone;
|
||||
function cloneArray(a, fn) {
|
||||
const keys = Object.keys(a);
|
||||
const a2 = new Array(keys.length);
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
const k = keys[i];
|
||||
const cur = a[k];
|
||||
if (typeof cur !== "object" || cur === null) a2[k] = cur;
|
||||
else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) a2[k] = handler(cur, fn);
|
||||
else if (ArrayBuffer.isView(cur)) a2[k] = copyBuffer(cur);
|
||||
else a2[k] = fn(cur);
|
||||
}
|
||||
return a2;
|
||||
}
|
||||
function clone(o) {
|
||||
if (typeof o !== "object" || o === null) return o;
|
||||
if (Array.isArray(o)) return cloneArray(o, clone);
|
||||
if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) return handler(o, clone);
|
||||
const o2 = {};
|
||||
for (const k in o) {
|
||||
if (Object.hasOwnProperty.call(o, k) === false) continue;
|
||||
const cur = o[k];
|
||||
if (typeof cur !== "object" || cur === null) o2[k] = cur;
|
||||
else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) o2[k] = handler(cur, clone);
|
||||
else if (ArrayBuffer.isView(cur)) o2[k] = copyBuffer(cur);
|
||||
else o2[k] = clone(cur);
|
||||
}
|
||||
return o2;
|
||||
}
|
||||
function cloneProto(o) {
|
||||
if (typeof o !== "object" || o === null) return o;
|
||||
if (Array.isArray(o)) return cloneArray(o, cloneProto);
|
||||
if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) return handler(o, cloneProto);
|
||||
const o2 = {};
|
||||
for (const k in o) {
|
||||
const cur = o[k];
|
||||
if (typeof cur !== "object" || cur === null) o2[k] = cur;
|
||||
else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) o2[k] = handler(cur, cloneProto);
|
||||
else if (ArrayBuffer.isView(cur)) o2[k] = copyBuffer(cur);
|
||||
else o2[k] = cloneProto(cur);
|
||||
}
|
||||
return o2;
|
||||
}
|
||||
}
|
||||
function rfdcCircles(opts) {
|
||||
const refs = [];
|
||||
const refsNew = [];
|
||||
const constructorHandlers = /* @__PURE__ */ new Map();
|
||||
constructorHandlers.set(Date, (o) => new Date(o));
|
||||
constructorHandlers.set(Map, (o, fn) => new Map(cloneArray(Array.from(o), fn)));
|
||||
constructorHandlers.set(Set, (o, fn) => new Set(cloneArray(Array.from(o), fn)));
|
||||
if (opts.constructorHandlers) for (const handler of opts.constructorHandlers) constructorHandlers.set(handler[0], handler[1]);
|
||||
let handler = null;
|
||||
return opts.proto ? cloneProto : clone;
|
||||
function cloneArray(a, fn) {
|
||||
const keys = Object.keys(a);
|
||||
const a2 = new Array(keys.length);
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
const k = keys[i];
|
||||
const cur = a[k];
|
||||
if (typeof cur !== "object" || cur === null) a2[k] = cur;
|
||||
else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) a2[k] = handler(cur, fn);
|
||||
else if (ArrayBuffer.isView(cur)) a2[k] = copyBuffer(cur);
|
||||
else {
|
||||
const index = refs.indexOf(cur);
|
||||
if (index !== -1) a2[k] = refsNew[index];
|
||||
else a2[k] = fn(cur);
|
||||
}
|
||||
}
|
||||
return a2;
|
||||
}
|
||||
function clone(o) {
|
||||
if (typeof o !== "object" || o === null) return o;
|
||||
if (Array.isArray(o)) return cloneArray(o, clone);
|
||||
if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) return handler(o, clone);
|
||||
const o2 = {};
|
||||
refs.push(o);
|
||||
refsNew.push(o2);
|
||||
for (const k in o) {
|
||||
if (Object.hasOwnProperty.call(o, k) === false) continue;
|
||||
const cur = o[k];
|
||||
if (typeof cur !== "object" || cur === null) o2[k] = cur;
|
||||
else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) o2[k] = handler(cur, clone);
|
||||
else if (ArrayBuffer.isView(cur)) o2[k] = copyBuffer(cur);
|
||||
else {
|
||||
const i = refs.indexOf(cur);
|
||||
if (i !== -1) o2[k] = refsNew[i];
|
||||
else o2[k] = clone(cur);
|
||||
}
|
||||
}
|
||||
refs.pop();
|
||||
refsNew.pop();
|
||||
return o2;
|
||||
}
|
||||
function cloneProto(o) {
|
||||
if (typeof o !== "object" || o === null) return o;
|
||||
if (Array.isArray(o)) return cloneArray(o, cloneProto);
|
||||
if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) return handler(o, cloneProto);
|
||||
const o2 = {};
|
||||
refs.push(o);
|
||||
refsNew.push(o2);
|
||||
for (const k in o) {
|
||||
const cur = o[k];
|
||||
if (typeof cur !== "object" || cur === null) o2[k] = cur;
|
||||
else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) o2[k] = handler(cur, cloneProto);
|
||||
else if (ArrayBuffer.isView(cur)) o2[k] = copyBuffer(cur);
|
||||
else {
|
||||
const i = refs.indexOf(cur);
|
||||
if (i !== -1) o2[k] = refsNew[i];
|
||||
else o2[k] = cloneProto(cur);
|
||||
}
|
||||
}
|
||||
refs.pop();
|
||||
refsNew.pop();
|
||||
return o2;
|
||||
}
|
||||
}
|
||||
})))(), 1);
|
||||
function NOOP() {}
|
||||
const isNumeric = (str) => `${+str}` === str;
|
||||
const isMacOS = () => navigator?.platform ? navigator?.platform.toLowerCase().includes("mac") : /Macintosh/.test(navigator.userAgent);
|
||||
const classifyRE = /(?:^|[-_/])(\w)/g;
|
||||
const camelizeRE = /-(\w)/g;
|
||||
const kebabizeRE = /([a-z0-9])([A-Z])/g;
|
||||
function toUpper(_, c) {
|
||||
return c ? c.toUpperCase() : "";
|
||||
}
|
||||
function classify(str) {
|
||||
return str && `${str}`.replace(classifyRE, toUpper);
|
||||
}
|
||||
function camelize(str) {
|
||||
return str && str.replace(camelizeRE, toUpper);
|
||||
}
|
||||
function kebabize(str) {
|
||||
return str && str.replace(kebabizeRE, (_, lowerCaseCharacter, upperCaseLetter) => {
|
||||
return `${lowerCaseCharacter}-${upperCaseLetter}`;
|
||||
}).toLowerCase();
|
||||
}
|
||||
function basename(filename, ext) {
|
||||
let normalizedFilename = filename.replace(/^[a-z]:/i, "").replace(/\\/g, "/");
|
||||
if (normalizedFilename.endsWith(`index${ext}`)) normalizedFilename = normalizedFilename.replace(`/index${ext}`, ext);
|
||||
const lastSlashIndex = normalizedFilename.lastIndexOf("/");
|
||||
const baseNameWithExt = normalizedFilename.substring(lastSlashIndex + 1);
|
||||
if (ext) {
|
||||
const extIndex = baseNameWithExt.lastIndexOf(ext);
|
||||
return baseNameWithExt.substring(0, extIndex);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
function sortByKey(state) {
|
||||
return state && state.slice().sort((a, b) => {
|
||||
if (a.key < b.key) return -1;
|
||||
if (a.key > b.key) return 1;
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
const HTTP_URL_RE = /^https?:\/\//;
|
||||
/**
|
||||
* Check a string is start with `/` or a valid http url
|
||||
*/
|
||||
function isUrlString(str) {
|
||||
return str.startsWith("/") || HTTP_URL_RE.test(str);
|
||||
}
|
||||
/**
|
||||
* @copyright [rfdc](https://github.com/davidmarkclements/rfdc)
|
||||
* @description A really fast deep clone alternative
|
||||
*/
|
||||
const deepClone = (0, import_rfdc.default)({ circles: true });
|
||||
function randomStr() {
|
||||
return Math.random().toString(36).slice(2);
|
||||
}
|
||||
function isObject(value) {
|
||||
return typeof value === "object" && !Array.isArray(value) && value !== null;
|
||||
}
|
||||
function isArray(value) {
|
||||
return Array.isArray(value);
|
||||
}
|
||||
function isSet(value) {
|
||||
return value instanceof Set;
|
||||
}
|
||||
function isMap(value) {
|
||||
return value instanceof Map;
|
||||
}
|
||||
//#endregion
|
||||
export { BROADCAST_CHANNEL_NAME, NOOP, VIEW_MODE_STORAGE_KEY, VITE_PLUGIN_CLIENT_URL_STORAGE_KEY, VITE_PLUGIN_DETECTED_STORAGE_KEY, basename, camelize, classify, deepClone, isArray, isBrowser, isInChromePanel, isInElectron, isInIframe, isInSeparateWindow, isMacOS, isMap, isNumeric, isNuxtApp, isObject, isSet, isUrlString, kebabize, randomStr, sortByKey, target };
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "@vue/devtools-shared",
|
||||
"type": "module",
|
||||
"version": "8.1.0",
|
||||
"author": "webfansplz",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"directory": "packages/shared",
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/vuejs/devtools.git"
|
||||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/index.js",
|
||||
"require": "./dist/index.cjs"
|
||||
}
|
||||
},
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@types/node": "^24.7.2",
|
||||
"rfdc": "^1.4.1"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsdown",
|
||||
"prepare:type": "tsdown --dts-only",
|
||||
"stub": "tsdown --watch --onSuccess 'tsdown --dts-only'"
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021-present Johnson Chu
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+160
@@ -0,0 +1,160 @@
|
||||
# @vue/language-core
|
||||
|
||||
<p>
|
||||
<a href="https://www.npmjs.com/package/@vue/language-core"><img src="https://img.shields.io/npm/v/@vue/language-core.svg?labelColor=18181B&color=1584FC" alt="NPM version"></a>
|
||||
<a href="https://github.com/vuejs/language-tools/blob/master/LICENSE"><img src="https://img.shields.io/github/license/vuejs/language-tools.svg?labelColor=18181B&color=1584FC" alt="License"></a>
|
||||
</p>
|
||||
|
||||
The core module for Vue Language Tools, responsible for parsing Vue Single File Components (SFCs) and transforming them into virtual code structures that TypeScript can understand. This package is a low-level dependency for `@vue/language-server` and `vue-tsc`.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
npm install @vue/language-core
|
||||
```
|
||||
|
||||
## Core API
|
||||
|
||||
### `createVueLanguagePlugin`
|
||||
|
||||
Creates a Vue language plugin for integration with Volar language services.
|
||||
|
||||
```typescript
|
||||
import { createVueLanguagePlugin } from '@vue/language-core';
|
||||
import type { LanguagePlugin } from '@volar/language-core';
|
||||
import ts from 'typescript';
|
||||
|
||||
const plugin: LanguagePlugin<string> = createVueLanguagePlugin(
|
||||
ts,
|
||||
compilerOptions, // ts.CompilerOptions
|
||||
vueCompilerOptions, // VueCompilerOptions
|
||||
(scriptId) => scriptId // asFileName: Converts scriptId to a file name
|
||||
);
|
||||
```
|
||||
|
||||
### `createParsedCommandLine`
|
||||
|
||||
Parses TypeScript and Vue compiler options from `tsconfig.json`.
|
||||
|
||||
```typescript
|
||||
import { createParsedCommandLine } from '@vue/language-core';
|
||||
import ts from 'typescript';
|
||||
|
||||
const parsed = createParsedCommandLine(ts, ts.sys, '/path/to/tsconfig.json');
|
||||
// parsed.options: ts.CompilerOptions
|
||||
// parsed.vueOptions: VueCompilerOptions
|
||||
```
|
||||
|
||||
### `parse`
|
||||
|
||||
Parses Vue SFC source code and returns an `SFCParseResult`.
|
||||
|
||||
```typescript
|
||||
import { parse } from '@vue/language-core';
|
||||
|
||||
const result = parse(`
|
||||
<template>
|
||||
<div>{{ msg }}</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
const msg = 'Hello'
|
||||
</script>
|
||||
`);
|
||||
|
||||
// result.descriptor.template
|
||||
// result.descriptor.scriptSetup
|
||||
// result.descriptor.styles
|
||||
// result.errors
|
||||
```
|
||||
|
||||
## `vueCompilerOptions`
|
||||
|
||||
Configure Vue compiler behavior through the `vueCompilerOptions` field in `tsconfig.json`:
|
||||
|
||||
```jsonc
|
||||
{
|
||||
"compilerOptions": { /* ... */ },
|
||||
"vueCompilerOptions": {
|
||||
"target": 3.5,
|
||||
"strictTemplates": true,
|
||||
"plugins": ["@vue/language-plugin-pug"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### File Handling Options
|
||||
|
||||
| Option | Type | Default | Description |
|
||||
| :--- | :--- | :--- | :--- |
|
||||
| `target` | `number \| 'auto'` | `'auto'` | Vue version. `'auto'` reads from `node_modules/vue/package.json`. |
|
||||
| `extensions` | `string[]` | `['.vue']` | File extensions to be treated as Vue SFCs. |
|
||||
| `vitePressExtensions` | `string[]` | `[]` | File extensions to be treated as VitePress Markdown. |
|
||||
| `petiteVueExtensions` | `string[]` | `[]` | File extensions to be treated as Petite Vue HTML. |
|
||||
| `plugins` | `string[]` | `[]` | Custom language plugins, e.g., [`@vue/language-plugin-pug`](../language-plugin-pug). |
|
||||
|
||||
### Type Checking Options
|
||||
|
||||
| Option | Type | Default | Description |
|
||||
| :--- | :--- | :--- | :--- |
|
||||
| `strictTemplates` | `boolean` | `false` | A convenience option that enables the four `check*` options below and `strictVModel`. |
|
||||
| `checkUnknownProps` | `boolean` | `false` | Check for unknown props. |
|
||||
| `checkUnknownEvents` | `boolean` | `false` | Check for unknown events. |
|
||||
| `checkUnknownComponents` | `boolean` | `false` | Check for unknown components. |
|
||||
| `checkUnknownDirectives` | `boolean` | `false` | Check for unknown directives. |
|
||||
| `strictVModel` | `boolean` | `false` | Strictly check v-model bindings. |
|
||||
| `strictCssModules` | `boolean` | `false` | Strictly check CSS Modules class names (not affected by `strictTemplates`). |
|
||||
|
||||
### Advanced Options
|
||||
|
||||
| Option | Type | Default | Description |
|
||||
| :--- | :--- | :--- | :--- |
|
||||
| `lib` | `string` | `'vue'` | Vue package name, used for generating import statements. |
|
||||
| `skipTemplateCodegen` | `boolean` | `false` | Skip virtual code generation for templates. |
|
||||
| `fallthroughAttributes` | `boolean` | `false` | Enable type inference for fallthrough attributes. |
|
||||
| `jsxSlots` | `boolean` | `false` | Use JSX-style slots types. |
|
||||
| `dataAttributes` | `string[]` | `[]` | Allowed data-* attribute patterns. |
|
||||
| `htmlAttributes` | `string[]` | `['aria-*']` | Allowed HTML attribute patterns. |
|
||||
| `resolveStyleImports` | `boolean` | `false` | Resolve import statements in styles. |
|
||||
| `resolveStyleClassNames` | `boolean \| 'scoped'` | `'scoped'` | Resolve class names in styles. |
|
||||
|
||||
## Built-in Plugins
|
||||
|
||||
This package includes the following built-in plugins to handle different file types and blocks:
|
||||
|
||||
### File Parsing Plugins
|
||||
|
||||
| Plugin | Function | Controlled By |
|
||||
| :--- | :--- | :--- |
|
||||
| `file-vue` | Parses `.vue` files into an SFC structure. | `extensions` |
|
||||
| `file-md` | Parses Markdown files into an SFC structure. | `vitePressExtensions` |
|
||||
| `file-html` | Parses HTML files into an SFC structure. | `petiteVueExtensions` |
|
||||
|
||||
### Virtual Code Generation Plugins
|
||||
|
||||
| Plugin | Function |
|
||||
| :--- | :--- |
|
||||
| `vue-tsx` | Generates TypeScript virtual code from an SFC. |
|
||||
| `vue-template-html` | Compiles HTML templates. |
|
||||
| `vue-template-inline-ts` | Handles TypeScript expressions in templates. |
|
||||
| `vue-template-inline-css` | Handles inline styles in templates. |
|
||||
| `vue-style-css` | Compiles CSS styles. |
|
||||
| `vue-script-js` | Handles JavaScript script blocks. |
|
||||
|
||||
### Embedded Code Extraction Plugins
|
||||
|
||||
| Plugin | Function |
|
||||
| :--- | :--- |
|
||||
| `vue-sfc-template` | Extracts the `<template>` block. |
|
||||
| `vue-sfc-styles` | Extracts `<style>` blocks. |
|
||||
| `vue-sfc-scripts` | Extracts `<script>` blocks (for formatting). |
|
||||
| `vue-sfc-customblocks` | Extracts custom blocks. |
|
||||
|
||||
## Related Packages
|
||||
|
||||
- [`@vue/language-server`](../language-server) - Language Server
|
||||
- [`@vue/language-service`](../language-service) - Language Service
|
||||
- [`vue-tsc`](../tsc) - Command-line Type Checker
|
||||
|
||||
## License
|
||||
|
||||
[MIT](https://github.com/vuejs/language-tools/blob/master/LICENSE) License
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
export * from './lib/codegen/template';
|
||||
export * from './lib/compilerOptions';
|
||||
export * from './lib/languagePlugin';
|
||||
export * from './lib/parsers/scriptRanges';
|
||||
export * from './lib/parsers/scriptSetupRanges';
|
||||
export * from './lib/plugins';
|
||||
export * from './lib/types';
|
||||
export * from './lib/utils/collectBindings';
|
||||
export * from './lib/utils/forEachTemplateNode';
|
||||
export * from './lib/utils/parseSfc';
|
||||
export * from './lib/utils/shared';
|
||||
export * from './lib/virtualCode';
|
||||
export * as names from './lib/codegen/names';
|
||||
export { tsCodegen } from './lib/plugins/vue-tsx';
|
||||
export * from '@volar/language-core';
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.tsCodegen = exports.names = void 0;
|
||||
__exportStar(require("./lib/codegen/template"), exports);
|
||||
__exportStar(require("./lib/compilerOptions"), exports);
|
||||
__exportStar(require("./lib/languagePlugin"), exports);
|
||||
__exportStar(require("./lib/parsers/scriptRanges"), exports);
|
||||
__exportStar(require("./lib/parsers/scriptSetupRanges"), exports);
|
||||
__exportStar(require("./lib/plugins"), exports);
|
||||
__exportStar(require("./lib/types"), exports);
|
||||
__exportStar(require("./lib/utils/collectBindings"), exports);
|
||||
__exportStar(require("./lib/utils/forEachTemplateNode"), exports);
|
||||
__exportStar(require("./lib/utils/parseSfc"), exports);
|
||||
__exportStar(require("./lib/utils/shared"), exports);
|
||||
__exportStar(require("./lib/virtualCode"), exports);
|
||||
exports.names = __importStar(require("./lib/codegen/names"));
|
||||
const vue_tsx_1 = require("./lib/plugins/vue-tsx");
|
||||
Object.defineProperty(exports, "tsCodegen", { enumerable: true, get: function () { return vue_tsx_1.tsCodegen; } });
|
||||
__exportStar(require("@volar/language-core"), exports);
|
||||
//# sourceMappingURL=index.js.map
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
import type { VueCodeInformation } from '../types';
|
||||
export declare const codeFeatures: {
|
||||
all: VueCodeInformation;
|
||||
importCompletionOnly: VueCodeInformation;
|
||||
verification: VueCodeInformation;
|
||||
completion: VueCodeInformation;
|
||||
withoutCompletion: VueCodeInformation;
|
||||
navigation: VueCodeInformation;
|
||||
navigationWithoutRename: VueCodeInformation;
|
||||
navigationAndCompletion: VueCodeInformation;
|
||||
navigationAndVerification: VueCodeInformation;
|
||||
withoutNavigation: VueCodeInformation;
|
||||
semanticWithoutHighlight: VueCodeInformation;
|
||||
withoutHighlight: VueCodeInformation;
|
||||
withoutHighlightAndCompletion: VueCodeInformation;
|
||||
withoutSemantic: VueCodeInformation;
|
||||
doNotReportTs2339AndTs2551: VueCodeInformation;
|
||||
doNotReportTs2353AndTs2561: VueCodeInformation;
|
||||
doNotReportTs6133: VueCodeInformation;
|
||||
};
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.codeFeatures = void 0;
|
||||
const raw = {
|
||||
all: {
|
||||
verification: true,
|
||||
completion: true,
|
||||
semantic: true,
|
||||
navigation: true,
|
||||
},
|
||||
importCompletionOnly: {
|
||||
__importCompletion: true,
|
||||
},
|
||||
verification: {
|
||||
verification: true,
|
||||
},
|
||||
completion: {
|
||||
completion: true,
|
||||
},
|
||||
withoutCompletion: {
|
||||
verification: true,
|
||||
semantic: true,
|
||||
navigation: true,
|
||||
},
|
||||
navigation: {
|
||||
navigation: true,
|
||||
},
|
||||
navigationWithoutRename: {
|
||||
navigation: { shouldRename: () => false },
|
||||
},
|
||||
navigationAndCompletion: {
|
||||
navigation: true,
|
||||
completion: true,
|
||||
},
|
||||
navigationAndVerification: {
|
||||
navigation: true,
|
||||
verification: true,
|
||||
},
|
||||
withoutNavigation: {
|
||||
verification: true,
|
||||
completion: true,
|
||||
semantic: true,
|
||||
},
|
||||
semanticWithoutHighlight: {
|
||||
semantic: { shouldHighlight: () => false },
|
||||
},
|
||||
withoutHighlight: {
|
||||
semantic: { shouldHighlight: () => false },
|
||||
verification: true,
|
||||
navigation: true,
|
||||
completion: true,
|
||||
},
|
||||
withoutHighlightAndCompletion: {
|
||||
semantic: { shouldHighlight: () => false },
|
||||
verification: true,
|
||||
navigation: true,
|
||||
},
|
||||
withoutSemantic: {
|
||||
verification: true,
|
||||
navigation: true,
|
||||
completion: true,
|
||||
},
|
||||
doNotReportTs2339AndTs2551: {
|
||||
verification: {
|
||||
// https://typescript.tv/errors/#ts2339
|
||||
// https://typescript.tv/errors/#ts2551
|
||||
shouldReport: (_source, code) => String(code) !== '2339' && String(code) !== '2551',
|
||||
},
|
||||
},
|
||||
doNotReportTs2353AndTs2561: {
|
||||
verification: {
|
||||
// https://typescript.tv/errors/#ts2353
|
||||
// https://typescript.tv/errors/#ts2561
|
||||
shouldReport: (_source, code) => String(code) !== '2353' && String(code) !== '2561',
|
||||
},
|
||||
},
|
||||
doNotReportTs6133: {
|
||||
verification: {
|
||||
// https://typescript.tv/errors/#ts6133
|
||||
shouldReport: (_source, code) => String(code) !== '6133',
|
||||
},
|
||||
},
|
||||
};
|
||||
exports.codeFeatures = raw;
|
||||
//# sourceMappingURL=codeFeatures.js.map
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import type * as CompilerDOM from '@vue/compiler-dom';
|
||||
export interface InlayHintInfo {
|
||||
blockName: string;
|
||||
offset: number;
|
||||
setting: string;
|
||||
label: string;
|
||||
tooltip?: string;
|
||||
paddingRight?: boolean;
|
||||
paddingLeft?: boolean;
|
||||
}
|
||||
export declare function createVBindShorthandInlayHintInfo(loc: CompilerDOM.SourceLocation, variableName: string): InlayHintInfo;
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createVBindShorthandInlayHintInfo = createVBindShorthandInlayHintInfo;
|
||||
function createVBindShorthandInlayHintInfo(loc, variableName) {
|
||||
return {
|
||||
blockName: 'template',
|
||||
offset: loc.end.offset,
|
||||
setting: 'vue.inlayHints.vBindShorthand',
|
||||
label: `="${variableName}"`,
|
||||
tooltip: [
|
||||
`This is a shorthand for \`${loc.source}="${variableName}"\`.`,
|
||||
'To hide this hint, set `vue.inlayHints.vBindShorthand` to `false` in IDE settings.',
|
||||
'[More info](https://github.com/vuejs/core/pull/9451)',
|
||||
].join('\n\n'),
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=inlayHints.js.map
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import type { VueCompilerOptions } from '../types';
|
||||
export declare function getLocalTypesGenerator(vueCompilerOptions: VueCompilerOptions): {
|
||||
generate: () => Generator<string, void, unknown>;
|
||||
readonly PrettifyLocal: string;
|
||||
readonly WithDefaults: string;
|
||||
readonly WithSlots: string;
|
||||
readonly PropsChildren: string;
|
||||
readonly TypePropsToOption: string;
|
||||
readonly OmitIndexSignature: string;
|
||||
};
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getLocalTypesGenerator = getLocalTypesGenerator;
|
||||
const utils_1 = require("./utils");
|
||||
function getLocalTypesGenerator(vueCompilerOptions) {
|
||||
const used = new Set();
|
||||
const WithDefaults = defineHelper(`__VLS_WithDefaults`, () => `
|
||||
type __VLS_WithDefaults<P, D> = {
|
||||
[K in keyof Pick<P, keyof P>]: K extends keyof D
|
||||
? ${PrettifyLocal.name}<P[K] & { default: D[K] }>
|
||||
: P[K]
|
||||
};
|
||||
`.trimStart());
|
||||
const PrettifyLocal = defineHelper(`__VLS_PrettifyLocal`, () => `type __VLS_PrettifyLocal<T> = (T extends any ? { [K in keyof T]: T[K]; } : { [K in keyof T as K]: T[K]; }) & {}${utils_1.endOfLine}`);
|
||||
const WithSlots = defineHelper(`__VLS_WithSlots`, () => `
|
||||
type __VLS_WithSlots<T, S> = T & {
|
||||
new(): {
|
||||
$slots: S;
|
||||
}
|
||||
};
|
||||
`.trimStart());
|
||||
const PropsChildren = defineHelper(`__VLS_PropsChildren`, () => `
|
||||
type __VLS_PropsChildren<S> = {
|
||||
[K in keyof (
|
||||
boolean extends (
|
||||
// @ts-ignore
|
||||
JSX.ElementChildrenAttribute extends never
|
||||
? true
|
||||
: false
|
||||
)
|
||||
? never
|
||||
// @ts-ignore
|
||||
: JSX.ElementChildrenAttribute
|
||||
)]?: S;
|
||||
};
|
||||
`.trimStart());
|
||||
const TypePropsToOption = defineHelper(`__VLS_TypePropsToOption`, () => `
|
||||
type __VLS_TypePropsToOption<T> = {
|
||||
[K in keyof T]-?: {} extends Pick<T, K>
|
||||
? { type: import('${vueCompilerOptions.lib}').PropType<Required<T>[K]> }
|
||||
: { type: import('${vueCompilerOptions.lib}').PropType<T[K]>, required: true }
|
||||
};
|
||||
`.trimStart());
|
||||
const OmitIndexSignature = defineHelper(`__VLS_OmitIndexSignature`, () => `type __VLS_OmitIndexSignature<T> = { [K in keyof T as {} extends Record<K, unknown> ? never : K]: T[K]; }${utils_1.endOfLine}`);
|
||||
const helpers = {
|
||||
[PrettifyLocal.name]: PrettifyLocal,
|
||||
[WithDefaults.name]: WithDefaults,
|
||||
[WithSlots.name]: WithSlots,
|
||||
[PropsChildren.name]: PropsChildren,
|
||||
[TypePropsToOption.name]: TypePropsToOption,
|
||||
[OmitIndexSignature.name]: OmitIndexSignature,
|
||||
};
|
||||
used.clear();
|
||||
return {
|
||||
generate,
|
||||
get PrettifyLocal() {
|
||||
return PrettifyLocal.name;
|
||||
},
|
||||
get WithDefaults() {
|
||||
return WithDefaults.name;
|
||||
},
|
||||
get WithSlots() {
|
||||
return WithSlots.name;
|
||||
},
|
||||
get PropsChildren() {
|
||||
return PropsChildren.name;
|
||||
},
|
||||
get TypePropsToOption() {
|
||||
return TypePropsToOption.name;
|
||||
},
|
||||
get OmitIndexSignature() {
|
||||
return OmitIndexSignature.name;
|
||||
},
|
||||
};
|
||||
function* generate() {
|
||||
for (const name of used) {
|
||||
yield helpers[name].generate();
|
||||
}
|
||||
used.clear();
|
||||
}
|
||||
function defineHelper(name, generate) {
|
||||
return {
|
||||
get name() {
|
||||
used.add(name);
|
||||
return name;
|
||||
},
|
||||
generate,
|
||||
};
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=localTypes.js.map
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
export declare const ctx = "__VLS_ctx";
|
||||
export declare const dollars = "__VLS_dollars";
|
||||
export declare const slots = "__VLS_slots";
|
||||
export declare const props = "__VLS_props";
|
||||
export declare const defaults = "__VLS_defaults";
|
||||
export declare const defaultModels = "__VLS_defaultModels";
|
||||
export declare const modelEmit = "__VLS_modelEmit";
|
||||
export declare const emit = "__VLS_emit";
|
||||
export declare const exposed = "__VLS_exposed";
|
||||
export declare const setup = "__VLS_setup";
|
||||
export declare const components = "__VLS_components";
|
||||
export declare const directives = "__VLS_directives";
|
||||
export declare const intrinsics = "__VLS_intrinsics";
|
||||
export declare const _export = "__VLS_export";
|
||||
export declare const ModelProps = "__VLS_ModelProps";
|
||||
export declare const Props = "__VLS_Props";
|
||||
export declare const Slots = "__VLS_Slots";
|
||||
export declare const InheritedAttrs = "__VLS_InheritedAttrs";
|
||||
export declare const TemplateRefs = "__VLS_TemplateRefs";
|
||||
export declare const RootEl = "__VLS_RootEl";
|
||||
export declare const ModelEmit = "__VLS_ModelEmit";
|
||||
export declare const EmitProps = "__VLS_EmitProps";
|
||||
export declare const Emit = "__VLS_Emit";
|
||||
export declare const SetupExposed = "__VLS_SetupExposed";
|
||||
export declare const PublicProps = "__VLS_PublicProps";
|
||||
export declare const StyleModules = "__VLS_StyleModules";
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.StyleModules = exports.PublicProps = exports.SetupExposed = exports.Emit = exports.EmitProps = exports.ModelEmit = exports.RootEl = exports.TemplateRefs = exports.InheritedAttrs = exports.Slots = exports.Props = exports.ModelProps = exports._export = exports.intrinsics = exports.directives = exports.components = exports.setup = exports.exposed = exports.emit = exports.modelEmit = exports.defaultModels = exports.defaults = exports.props = exports.slots = exports.dollars = exports.ctx = void 0;
|
||||
exports.ctx = '__VLS_ctx';
|
||||
exports.dollars = '__VLS_dollars';
|
||||
exports.slots = '__VLS_slots';
|
||||
exports.props = '__VLS_props';
|
||||
exports.defaults = '__VLS_defaults';
|
||||
exports.defaultModels = '__VLS_defaultModels';
|
||||
exports.modelEmit = '__VLS_modelEmit';
|
||||
exports.emit = '__VLS_emit';
|
||||
exports.exposed = '__VLS_exposed';
|
||||
exports.setup = '__VLS_setup';
|
||||
exports.components = '__VLS_components';
|
||||
exports.directives = '__VLS_directives';
|
||||
exports.intrinsics = '__VLS_intrinsics';
|
||||
exports._export = '__VLS_export';
|
||||
exports.ModelProps = '__VLS_ModelProps';
|
||||
exports.Props = '__VLS_Props';
|
||||
exports.Slots = '__VLS_Slots';
|
||||
exports.InheritedAttrs = '__VLS_InheritedAttrs';
|
||||
exports.TemplateRefs = '__VLS_TemplateRefs';
|
||||
exports.RootEl = '__VLS_RootEl';
|
||||
exports.ModelEmit = '__VLS_ModelEmit';
|
||||
exports.EmitProps = '__VLS_EmitProps';
|
||||
exports.Emit = '__VLS_Emit';
|
||||
exports.SetupExposed = '__VLS_SetupExposed';
|
||||
exports.PublicProps = '__VLS_PublicProps';
|
||||
exports.StyleModules = '__VLS_StyleModules';
|
||||
//# sourceMappingURL=names.js.map
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
|
||||
import type { Code, Sfc } from '../../types';
|
||||
import type { ScriptCodegenContext } from './context';
|
||||
import type { ScriptCodegenOptions } from './index';
|
||||
export declare function generateComponent(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
|
||||
+147
@@ -0,0 +1,147 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateComponent = generateComponent;
|
||||
const codeFeatures_1 = require("../codeFeatures");
|
||||
const names = __importStar(require("../names"));
|
||||
const utils_1 = require("../utils");
|
||||
const merge_1 = require("../utils/merge");
|
||||
function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
|
||||
yield `(await import('${options.vueCompilerOptions.lib}')).defineComponent({${utils_1.newLine}`;
|
||||
const returns = [];
|
||||
if (scriptSetupRanges.defineExpose) {
|
||||
returns.push([names.exposed]);
|
||||
}
|
||||
if (returns.length) {
|
||||
yield `setup: () => (`;
|
||||
yield* (0, merge_1.generateSpreadMerge)(returns);
|
||||
yield `),${utils_1.newLine}`;
|
||||
}
|
||||
const emitOptionCodes = [...generateEmitsOption(options, scriptSetupRanges)];
|
||||
yield* emitOptionCodes;
|
||||
yield* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, !!emitOptionCodes.length);
|
||||
if (options.vueCompilerOptions.target >= 3.5
|
||||
&& options.vueCompilerOptions.inferComponentDollarRefs
|
||||
&& options.templateAndStyleTypes.has(names.TemplateRefs)) {
|
||||
yield `__typeRefs: {} as ${names.TemplateRefs},${utils_1.newLine}`;
|
||||
}
|
||||
if (options.vueCompilerOptions.target >= 3.5
|
||||
&& options.vueCompilerOptions.inferComponentDollarEl
|
||||
&& options.templateAndStyleTypes.has(names.RootEl)) {
|
||||
yield `__typeEl: {} as ${names.RootEl},${utils_1.newLine}`;
|
||||
}
|
||||
yield `})`;
|
||||
}
|
||||
function* generateEmitsOption(options, scriptSetupRanges) {
|
||||
const optionCodes = [];
|
||||
const typeOptionCodes = [];
|
||||
if (scriptSetupRanges.defineModel.length) {
|
||||
optionCodes.push([`{} as __VLS_NormalizeEmits<typeof ${names.modelEmit}>`]);
|
||||
typeOptionCodes.push([names.ModelEmit]);
|
||||
}
|
||||
if (scriptSetupRanges.defineEmits) {
|
||||
const { name, typeArg, hasUnionTypeArg } = scriptSetupRanges.defineEmits;
|
||||
optionCodes.push([`{} as __VLS_NormalizeEmits<typeof ${name ?? names.emit}>`]);
|
||||
if (typeArg && !hasUnionTypeArg) {
|
||||
typeOptionCodes.push([names.Emit]);
|
||||
}
|
||||
else {
|
||||
typeOptionCodes.length = 0;
|
||||
}
|
||||
}
|
||||
if (options.vueCompilerOptions.target >= 3.5 && typeOptionCodes.length) {
|
||||
yield `__typeEmits: {} as `;
|
||||
yield* (0, merge_1.generateIntersectMerge)(typeOptionCodes);
|
||||
yield `,${utils_1.newLine}`;
|
||||
}
|
||||
else if (optionCodes.length) {
|
||||
yield `emits: `;
|
||||
yield* (0, merge_1.generateSpreadMerge)(optionCodes);
|
||||
yield `,${utils_1.newLine}`;
|
||||
}
|
||||
}
|
||||
function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasEmitsOption) {
|
||||
const optionGenerates = [];
|
||||
const typeOptionGenerates = [];
|
||||
if (options.templateAndStyleTypes.has(names.InheritedAttrs)) {
|
||||
const attrsType = hasEmitsOption
|
||||
? `Omit<${names.InheritedAttrs}, keyof ${names.EmitProps}>`
|
||||
: names.InheritedAttrs;
|
||||
optionGenerates.push(function* () {
|
||||
const propsType = `__VLS_PickNotAny<${ctx.localTypes.OmitIndexSignature}<${attrsType}>, {}>`;
|
||||
const optionType = `${ctx.localTypes.TypePropsToOption}<${propsType}>`;
|
||||
yield `{} as ${optionType}`;
|
||||
});
|
||||
typeOptionGenerates.push(function* () {
|
||||
yield `{} as ${attrsType}`;
|
||||
});
|
||||
}
|
||||
if (ctx.generatedTypes.has(names.PublicProps)) {
|
||||
if (options.vueCompilerOptions.target < 3.6) {
|
||||
optionGenerates.push(function* () {
|
||||
let propsType = `${ctx.localTypes.TypePropsToOption}<${names.PublicProps}>`;
|
||||
if (scriptSetupRanges.withDefaults?.arg) {
|
||||
propsType = `${ctx.localTypes.WithDefaults}<${propsType}, typeof ${names.defaults}>`;
|
||||
}
|
||||
yield `{} as ${propsType}`;
|
||||
});
|
||||
}
|
||||
typeOptionGenerates.push(function* () {
|
||||
yield `{} as ${names.PublicProps}`;
|
||||
});
|
||||
}
|
||||
if (scriptSetupRanges.defineProps?.arg) {
|
||||
const { arg } = scriptSetupRanges.defineProps;
|
||||
optionGenerates.push(() => (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.navigation));
|
||||
typeOptionGenerates.length = 0;
|
||||
}
|
||||
const useTypeOption = options.vueCompilerOptions.target >= 3.5 && typeOptionGenerates.length;
|
||||
const useOption = (!useTypeOption || scriptSetupRanges.withDefaults) && optionGenerates.length;
|
||||
if (useTypeOption) {
|
||||
if (options.vueCompilerOptions.target >= 3.6
|
||||
&& scriptSetupRanges.withDefaults?.arg) {
|
||||
yield `__defaults: ${names.defaults},${utils_1.newLine}`;
|
||||
}
|
||||
yield `__typeProps: `;
|
||||
yield* (0, merge_1.generateSpreadMerge)(typeOptionGenerates.map(g => g()));
|
||||
yield `,${utils_1.newLine}`;
|
||||
}
|
||||
if (useOption) {
|
||||
yield `props: `;
|
||||
yield* (0, merge_1.generateSpreadMerge)(optionGenerates.map(g => g()));
|
||||
yield `,${utils_1.newLine}`;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=component.js.map
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import type { InlayHintInfo } from '../inlayHints';
|
||||
import type { ScriptCodegenOptions } from './index';
|
||||
export type ScriptCodegenContext = ReturnType<typeof createScriptCodegenContext>;
|
||||
export declare function createScriptCodegenContext(options: ScriptCodegenOptions): {
|
||||
generatedTypes: Set<string>;
|
||||
localTypes: {
|
||||
generate: () => Generator<string, void, unknown>;
|
||||
readonly PrettifyLocal: string;
|
||||
readonly WithDefaults: string;
|
||||
readonly WithSlots: string;
|
||||
readonly PropsChildren: string;
|
||||
readonly TypePropsToOption: string;
|
||||
readonly OmitIndexSignature: string;
|
||||
};
|
||||
inlayHints: InlayHintInfo[];
|
||||
};
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createScriptCodegenContext = createScriptCodegenContext;
|
||||
const localTypes_1 = require("../localTypes");
|
||||
function createScriptCodegenContext(options) {
|
||||
const localTypes = (0, localTypes_1.getLocalTypesGenerator)(options.vueCompilerOptions);
|
||||
const inlayHints = [];
|
||||
return {
|
||||
generatedTypes: new Set(),
|
||||
localTypes,
|
||||
inlayHints,
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=context.js.map
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
import type { ScriptRanges } from '../../parsers/scriptRanges';
|
||||
import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
|
||||
import type { Code, Sfc, VueCompilerOptions } from '../../types';
|
||||
export interface ScriptCodegenOptions {
|
||||
vueCompilerOptions: VueCompilerOptions;
|
||||
script: Sfc['script'];
|
||||
scriptSetup: Sfc['scriptSetup'];
|
||||
fileName: string;
|
||||
scriptRanges: ScriptRanges | undefined;
|
||||
scriptSetupRanges: ScriptSetupRanges | undefined;
|
||||
templateAndStyleTypes: Set<string>;
|
||||
templateAndStyleCodes: Code[];
|
||||
exposed: Set<string>;
|
||||
}
|
||||
export { generate as generateScript };
|
||||
declare function generate(options: ScriptCodegenOptions): {
|
||||
generatedTypes: Set<string>;
|
||||
localTypes: {
|
||||
generate: () => Generator<string, void, unknown>;
|
||||
readonly PrettifyLocal: string;
|
||||
readonly WithDefaults: string;
|
||||
readonly WithSlots: string;
|
||||
readonly PropsChildren: string;
|
||||
readonly TypePropsToOption: string;
|
||||
readonly OmitIndexSignature: string;
|
||||
};
|
||||
inlayHints: import("../inlayHints").InlayHintInfo[];
|
||||
codes: Code[];
|
||||
};
|
||||
+202
@@ -0,0 +1,202 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateScript = generate;
|
||||
const path = __importStar(require("path-browserify"));
|
||||
const codeFeatures_1 = require("../codeFeatures");
|
||||
const names = __importStar(require("../names"));
|
||||
const utils_1 = require("../utils");
|
||||
const boundary_1 = require("../utils/boundary");
|
||||
const context_1 = require("./context");
|
||||
const scriptSetup_1 = require("./scriptSetup");
|
||||
const template_1 = require("./template");
|
||||
const exportExpression = `{} as typeof ${names._export}`;
|
||||
function generate(options) {
|
||||
const ctx = (0, context_1.createScriptCodegenContext)(options);
|
||||
const codeGenerator = generateWorker(options, ctx);
|
||||
return { ...ctx, codes: [...codeGenerator] };
|
||||
}
|
||||
function* generateWorker(options, ctx) {
|
||||
const { script, scriptRanges, scriptSetup, scriptSetupRanges, vueCompilerOptions, fileName } = options;
|
||||
yield* generateGlobalTypesReference(vueCompilerOptions, fileName);
|
||||
// <script src="">
|
||||
if (typeof script?.src === 'object') {
|
||||
let src = script.src.text;
|
||||
if (src.endsWith('.ts') && !src.endsWith('.d.ts')) {
|
||||
src = src.slice(0, -'.ts'.length) + '.js';
|
||||
}
|
||||
else if (src.endsWith('.tsx')) {
|
||||
src = src.slice(0, -'.tsx'.length) + '.jsx';
|
||||
}
|
||||
yield `import __VLS_default from `;
|
||||
const token = yield* (0, boundary_1.startBoundary)('main', script.src.offset, {
|
||||
...codeFeatures_1.codeFeatures.all,
|
||||
...src !== script.src.text ? codeFeatures_1.codeFeatures.navigationWithoutRename : {},
|
||||
});
|
||||
yield `'`;
|
||||
yield [src.slice(0, script.src.text.length), 'main', script.src.offset, { __combineToken: token }];
|
||||
yield src.slice(script.src.text.length);
|
||||
yield `'`;
|
||||
yield (0, boundary_1.endBoundary)(token, script.src.offset + script.src.text.length);
|
||||
yield utils_1.endOfLine;
|
||||
yield `export default __VLS_default;${utils_1.endOfLine}`;
|
||||
yield* (0, template_1.generateTemplate)(options, ctx, '__VLS_default');
|
||||
}
|
||||
// <script> + <script setup>
|
||||
else if (script && scriptRanges && scriptSetup && scriptSetupRanges) {
|
||||
yield* (0, scriptSetup_1.generateScriptSetupImports)(scriptSetup, scriptSetupRanges);
|
||||
// <script>
|
||||
let selfType;
|
||||
const { exportDefault } = scriptRanges;
|
||||
if (exportDefault) {
|
||||
yield* generateScriptWithExportDefault(ctx, script, scriptRanges, exportDefault, vueCompilerOptions, selfType = '__VLS_self');
|
||||
}
|
||||
else {
|
||||
yield* (0, utils_1.generateSfcBlockSection)(script, 0, script.content.length, codeFeatures_1.codeFeatures.all);
|
||||
yield `export default ${exportExpression}${utils_1.endOfLine}`;
|
||||
}
|
||||
// <script setup>
|
||||
yield* generateExportDeclareEqual(scriptSetup, names._export);
|
||||
if (scriptSetup.generic) {
|
||||
yield* (0, scriptSetup_1.generateGeneric)(options, ctx, scriptSetup, scriptSetupRanges, scriptSetup.generic, (0, scriptSetup_1.generateSetupFunction)(options, ctx, scriptSetup, scriptSetupRanges, (0, template_1.generateTemplate)(options, ctx, selfType)));
|
||||
}
|
||||
else {
|
||||
yield `await (async () => {${utils_1.newLine}`;
|
||||
yield* (0, scriptSetup_1.generateSetupFunction)(options, ctx, scriptSetup, scriptSetupRanges, (0, template_1.generateTemplate)(options, ctx, selfType), [`return `]);
|
||||
yield `})()${utils_1.endOfLine}`;
|
||||
}
|
||||
}
|
||||
// only <script setup>
|
||||
else if (scriptSetup && scriptSetupRanges) {
|
||||
yield* (0, scriptSetup_1.generateScriptSetupImports)(scriptSetup, scriptSetupRanges);
|
||||
if (scriptSetup.generic) {
|
||||
yield* generateExportDeclareEqual(scriptSetup, names._export);
|
||||
yield* (0, scriptSetup_1.generateGeneric)(options, ctx, scriptSetup, scriptSetupRanges, scriptSetup.generic, (0, scriptSetup_1.generateSetupFunction)(options, ctx, scriptSetup, scriptSetupRanges, (0, template_1.generateTemplate)(options, ctx)));
|
||||
}
|
||||
else {
|
||||
// no script block, generate script setup code at root
|
||||
yield* (0, scriptSetup_1.generateSetupFunction)(options, ctx, scriptSetup, scriptSetupRanges, (0, template_1.generateTemplate)(options, ctx), generateExportDeclareEqual(scriptSetup, names._export));
|
||||
}
|
||||
yield `export default ${exportExpression}${utils_1.endOfLine}`;
|
||||
}
|
||||
// only <script>
|
||||
else if (script && scriptRanges) {
|
||||
const { exportDefault } = scriptRanges;
|
||||
if (exportDefault) {
|
||||
yield* generateScriptWithExportDefault(ctx, script, scriptRanges, exportDefault, vueCompilerOptions, names._export, (0, template_1.generateTemplate)(options, ctx, names._export));
|
||||
}
|
||||
else {
|
||||
yield* (0, utils_1.generateSfcBlockSection)(script, 0, script.content.length, codeFeatures_1.codeFeatures.all);
|
||||
yield* generateExportDeclareEqual(script, names._export);
|
||||
yield `(await import('${vueCompilerOptions.lib}')).defineComponent({})${utils_1.endOfLine}`;
|
||||
yield* (0, template_1.generateTemplate)(options, ctx, names._export);
|
||||
yield `export default ${exportExpression}${utils_1.endOfLine}`;
|
||||
}
|
||||
}
|
||||
yield* ctx.localTypes.generate();
|
||||
}
|
||||
function* generateScriptWithExportDefault(ctx, script, scriptRanges, exportDefault, vueCompilerOptions, varName, templateGenerator) {
|
||||
const componentOptions = scriptRanges.exportDefault?.options;
|
||||
const { expression, isObjectLiteral } = componentOptions ?? exportDefault;
|
||||
let wrapLeft;
|
||||
let wrapRight;
|
||||
if (isObjectLiteral
|
||||
&& vueCompilerOptions.optionsWrapper.length) {
|
||||
[wrapLeft, wrapRight] = vueCompilerOptions.optionsWrapper;
|
||||
ctx.inlayHints.push({
|
||||
blockName: script.name,
|
||||
offset: expression.start,
|
||||
setting: 'vue.inlayHints.optionsWrapper',
|
||||
label: wrapLeft || '[Missing optionsWrapper[0]]',
|
||||
tooltip: [
|
||||
'This is virtual code that is automatically wrapped for type support, it does not affect your runtime behavior, you can customize it via `vueCompilerOptions.optionsWrapper` option in tsconfig / jsconfig.',
|
||||
'To hide it, you can set `"vue.inlayHints.optionsWrapper": false` in IDE settings.',
|
||||
].join('\n\n'),
|
||||
}, {
|
||||
blockName: script.name,
|
||||
offset: expression.end,
|
||||
setting: 'vue.inlayHints.optionsWrapper',
|
||||
label: wrapRight || '[Missing optionsWrapper[1]]',
|
||||
});
|
||||
}
|
||||
yield* (0, utils_1.generateSfcBlockSection)(script, 0, expression.start, codeFeatures_1.codeFeatures.all);
|
||||
yield exportExpression;
|
||||
yield* (0, utils_1.generateSfcBlockSection)(script, expression.end, exportDefault.end, codeFeatures_1.codeFeatures.all);
|
||||
yield utils_1.endOfLine;
|
||||
if (templateGenerator) {
|
||||
yield* templateGenerator;
|
||||
}
|
||||
yield* generateExportDeclareEqual(script, varName);
|
||||
if (wrapLeft && wrapRight) {
|
||||
yield wrapLeft;
|
||||
yield* (0, utils_1.generateSfcBlockSection)(script, expression.start, expression.end, codeFeatures_1.codeFeatures.all);
|
||||
yield wrapRight;
|
||||
}
|
||||
else {
|
||||
yield* (0, utils_1.generateSfcBlockSection)(script, expression.start, expression.end, codeFeatures_1.codeFeatures.all);
|
||||
}
|
||||
yield utils_1.endOfLine;
|
||||
yield* (0, utils_1.generateSfcBlockSection)(script, exportDefault.end, script.content.length, codeFeatures_1.codeFeatures.all);
|
||||
}
|
||||
function* generateGlobalTypesReference({ typesRoot, lib, target, checkUnknownProps }, fileName) {
|
||||
let typesPath;
|
||||
if (path.isAbsolute(typesRoot)) {
|
||||
let relativePath = path.relative(path.dirname(fileName), typesRoot);
|
||||
if (relativePath !== typesRoot
|
||||
&& !relativePath.startsWith('./')
|
||||
&& !relativePath.startsWith('../')) {
|
||||
relativePath = './' + relativePath;
|
||||
}
|
||||
typesPath = relativePath;
|
||||
}
|
||||
else {
|
||||
typesPath = typesRoot;
|
||||
}
|
||||
yield `/// <reference types=${JSON.stringify(typesPath + '/template-helpers.d.ts')} />${utils_1.newLine}`;
|
||||
if (!checkUnknownProps) {
|
||||
yield `/// <reference types=${JSON.stringify(typesPath + '/props-fallback.d.ts')} />${utils_1.newLine}`;
|
||||
}
|
||||
if (lib === 'vue' && target < 3.5) {
|
||||
yield `/// <reference types=${JSON.stringify(typesPath + '/vue-3.4-shims.d.ts')} />${utils_1.newLine}`;
|
||||
}
|
||||
}
|
||||
function* generateExportDeclareEqual(block, name) {
|
||||
yield `const `;
|
||||
const token = yield* (0, boundary_1.startBoundary)(block.name, 0, codeFeatures_1.codeFeatures.doNotReportTs6133);
|
||||
yield name;
|
||||
yield (0, boundary_1.endBoundary)(token, block.content.length);
|
||||
yield ` = `;
|
||||
}
|
||||
//# sourceMappingURL=index.js.map
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
|
||||
import type { Code, Sfc } from '../../types';
|
||||
import type { ScriptCodegenContext } from './context';
|
||||
import type { ScriptCodegenOptions } from './index';
|
||||
export declare function generateScriptSetupImports(scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
|
||||
export declare function generateGeneric(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges, generic: NonNullable<NonNullable<Sfc['scriptSetup']>['generic']>, body: Iterable<Code>): Generator<Code>;
|
||||
export declare function generateSetupFunction(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges, body: Iterable<Code>, output?: Iterable<Code>): Generator<Code>;
|
||||
+424
@@ -0,0 +1,424 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateScriptSetupImports = generateScriptSetupImports;
|
||||
exports.generateGeneric = generateGeneric;
|
||||
exports.generateSetupFunction = generateSetupFunction;
|
||||
const shared_1 = require("@vue/shared");
|
||||
const codeFeatures_1 = require("../codeFeatures");
|
||||
const names = __importStar(require("../names"));
|
||||
const utils_1 = require("../utils");
|
||||
const boundary_1 = require("../utils/boundary");
|
||||
const camelized_1 = require("../utils/camelized");
|
||||
const transform_1 = require("../utils/transform");
|
||||
const component_1 = require("./component");
|
||||
function* generateScriptSetupImports(scriptSetup, scriptSetupRanges) {
|
||||
yield [
|
||||
scriptSetup.content.slice(0, Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset)),
|
||||
'scriptSetup',
|
||||
0,
|
||||
codeFeatures_1.codeFeatures.all,
|
||||
];
|
||||
}
|
||||
function* generateGeneric(options, ctx, scriptSetup, scriptSetupRanges, generic, body) {
|
||||
yield `(`;
|
||||
if (typeof generic === 'object') {
|
||||
yield `<`;
|
||||
yield [generic.text, 'main', generic.offset, codeFeatures_1.codeFeatures.all];
|
||||
if (!generic.text.endsWith(`,`)) {
|
||||
yield `,`;
|
||||
}
|
||||
yield `>`;
|
||||
}
|
||||
yield `(${utils_1.newLine}`
|
||||
+ ` ${names.props}: NonNullable<Awaited<typeof ${names.setup}>>['props'],${utils_1.newLine}`
|
||||
+ ` ${names.ctx}?: ${ctx.localTypes.PrettifyLocal}<Pick<NonNullable<Awaited<typeof ${names.setup}>>, 'attrs' | 'emit' | 'slots'>>,${utils_1.newLine}` // use __VLS_Prettify for less dts code
|
||||
+ ` ${names.exposed}?: NonNullable<Awaited<typeof ${names.setup}>>['expose'],${utils_1.newLine}`
|
||||
+ ` ${names.setup} = (async () => {${utils_1.newLine}`;
|
||||
yield* body;
|
||||
const propTypes = [];
|
||||
const emitTypes = [];
|
||||
const { vueCompilerOptions } = options;
|
||||
if (ctx.generatedTypes.has(names.PublicProps)) {
|
||||
propTypes.push(names.PublicProps);
|
||||
}
|
||||
if (scriptSetupRanges.defineProps?.arg) {
|
||||
yield `const __VLS_propsOption = `;
|
||||
yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.defineProps.arg.start, scriptSetupRanges.defineProps.arg.end, codeFeatures_1.codeFeatures.navigation);
|
||||
yield utils_1.endOfLine;
|
||||
propTypes.push(`import('${vueCompilerOptions.lib}').${vueCompilerOptions.target >= 3.3 ? `ExtractPublicPropTypes` : `ExtractPropTypes`}<typeof __VLS_propsOption>`);
|
||||
}
|
||||
if (scriptSetupRanges.defineEmits || scriptSetupRanges.defineModel.length) {
|
||||
propTypes.push(names.EmitProps);
|
||||
}
|
||||
if (options.templateAndStyleTypes.has(names.InheritedAttrs)) {
|
||||
propTypes.push(names.InheritedAttrs);
|
||||
}
|
||||
if (scriptSetupRanges.defineEmits) {
|
||||
emitTypes.push(`typeof ${scriptSetupRanges.defineEmits.name ?? names.emit}`);
|
||||
}
|
||||
if (scriptSetupRanges.defineModel.length) {
|
||||
emitTypes.push(`typeof ${names.modelEmit}`);
|
||||
}
|
||||
yield `return {} as {${utils_1.newLine}`;
|
||||
yield ` props: `;
|
||||
yield vueCompilerOptions.target >= 3.4
|
||||
? `import('${vueCompilerOptions.lib}').PublicProps`
|
||||
: vueCompilerOptions.target >= 3
|
||||
? `import('${vueCompilerOptions.lib}').VNodeProps`
|
||||
+ ` & import('${vueCompilerOptions.lib}').AllowedComponentProps`
|
||||
+ ` & import('${vueCompilerOptions.lib}').ComponentCustomProps`
|
||||
: `globalThis.JSX.IntrinsicAttributes`;
|
||||
if (propTypes.length) {
|
||||
yield ` & ${ctx.localTypes.PrettifyLocal}<${propTypes.join(` & `)}>`;
|
||||
}
|
||||
yield ` & (typeof globalThis extends { __VLS_PROPS_FALLBACK: infer P } ? P : {})${utils_1.endOfLine}`;
|
||||
yield ` expose: (exposed: `;
|
||||
yield scriptSetupRanges.defineExpose
|
||||
? `import('${vueCompilerOptions.lib}').ShallowUnwrapRef<typeof ${names.exposed}>`
|
||||
: `{}`;
|
||||
if (options.vueCompilerOptions.inferComponentDollarRefs
|
||||
&& options.templateAndStyleTypes.has(names.TemplateRefs)) {
|
||||
yield ` & { $refs: ${names.TemplateRefs}; }`;
|
||||
}
|
||||
if (options.vueCompilerOptions.inferComponentDollarEl
|
||||
&& options.templateAndStyleTypes.has(names.RootEl)) {
|
||||
yield ` & { $el: ${names.RootEl}; }`;
|
||||
}
|
||||
yield `) => void${utils_1.endOfLine}`;
|
||||
yield ` attrs: any${utils_1.endOfLine}`;
|
||||
yield ` slots: ${hasSlotsType(options) ? names.Slots : `{}`}${utils_1.endOfLine}`;
|
||||
yield ` emit: ${emitTypes.length ? emitTypes.join(` & `) : `{}`}${utils_1.endOfLine}`;
|
||||
yield `}${utils_1.endOfLine}`;
|
||||
yield `})(),${utils_1.newLine}`; // __VLS_setup = (async () => {
|
||||
yield `) => ({} as import('${vueCompilerOptions.lib}').VNode & { __ctx?: Awaited<typeof ${names.setup}> }))${utils_1.endOfLine}`;
|
||||
}
|
||||
function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, body, output) {
|
||||
const transforms = [];
|
||||
if (scriptSetupRanges.defineProps) {
|
||||
const { name, statement, callExp, typeArg } = scriptSetupRanges.defineProps;
|
||||
const _callExp = scriptSetupRanges.withDefaults?.callExp ?? callExp;
|
||||
transforms.push(...generateDefineWithTypeTransforms(scriptSetup, statement, _callExp, typeArg, name, names.props, names.Props));
|
||||
}
|
||||
if (scriptSetupRanges.defineEmits) {
|
||||
const { name, statement, callExp, typeArg } = scriptSetupRanges.defineEmits;
|
||||
transforms.push(...generateDefineWithTypeTransforms(scriptSetup, statement, callExp, typeArg, name, names.emit, names.Emit));
|
||||
}
|
||||
if (scriptSetupRanges.defineSlots) {
|
||||
const { name, statement, callExp, typeArg } = scriptSetupRanges.defineSlots;
|
||||
transforms.push(...generateDefineWithTypeTransforms(scriptSetup, statement, callExp, typeArg, name, names.slots, names.Slots));
|
||||
}
|
||||
if (scriptSetupRanges.defineExpose) {
|
||||
const { callExp, arg, typeArg } = scriptSetupRanges.defineExpose;
|
||||
if (typeArg) {
|
||||
transforms.push((0, transform_1.insert)(callExp.start, function* () {
|
||||
yield `let ${names.exposed}!: `;
|
||||
yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.start, typeArg.end, codeFeatures_1.codeFeatures.all);
|
||||
yield utils_1.endOfLine;
|
||||
}), (0, transform_1.replace)(typeArg.start, typeArg.end, function* () {
|
||||
yield `typeof ${names.exposed}`;
|
||||
}));
|
||||
}
|
||||
else if (arg) {
|
||||
transforms.push((0, transform_1.insert)(callExp.start, function* () {
|
||||
yield `const ${names.exposed} = `;
|
||||
yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.all);
|
||||
yield utils_1.endOfLine;
|
||||
}), (0, transform_1.replace)(arg.start, arg.end, function* () {
|
||||
yield `${names.exposed}`;
|
||||
}));
|
||||
}
|
||||
else {
|
||||
transforms.push((0, transform_1.insert)(callExp.start, function* () {
|
||||
yield `const ${names.exposed} = {}${utils_1.endOfLine}`;
|
||||
}));
|
||||
}
|
||||
}
|
||||
if (options.vueCompilerOptions.inferTemplateDollarAttrs) {
|
||||
for (const { callExp } of scriptSetupRanges.useAttrs) {
|
||||
transforms.push((0, transform_1.insert)(callExp.start, function* () {
|
||||
yield `(`;
|
||||
}), (0, transform_1.insert)(callExp.end, function* () {
|
||||
yield ` as typeof ${names.dollars}.$attrs)`;
|
||||
}));
|
||||
}
|
||||
}
|
||||
for (const { callExp, exp, arg } of scriptSetupRanges.useCssModule) {
|
||||
transforms.push((0, transform_1.insert)(callExp.start, function* () {
|
||||
yield `(`;
|
||||
}));
|
||||
const type = options.templateAndStyleTypes.has(names.StyleModules)
|
||||
? names.StyleModules
|
||||
: `{}`;
|
||||
if (arg) {
|
||||
transforms.push((0, transform_1.insert)(callExp.end, function* () {
|
||||
yield ` as Omit<${type}, '$style'>[`;
|
||||
yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.withoutSemantic);
|
||||
yield `])`;
|
||||
}), (0, transform_1.replace)(arg.start, arg.end, function* () {
|
||||
yield `{} as any`;
|
||||
}));
|
||||
}
|
||||
else {
|
||||
transforms.push((0, transform_1.insert)(callExp.end, function* () {
|
||||
yield ` as ${type}[`;
|
||||
const token = yield* (0, boundary_1.startBoundary)(scriptSetup.name, exp.start, codeFeatures_1.codeFeatures.verification);
|
||||
yield `'$style'`;
|
||||
yield (0, boundary_1.endBoundary)(token, exp.end);
|
||||
yield `])`;
|
||||
}));
|
||||
}
|
||||
}
|
||||
if (options.vueCompilerOptions.inferTemplateDollarSlots) {
|
||||
for (const { callExp } of scriptSetupRanges.useSlots) {
|
||||
transforms.push((0, transform_1.insert)(callExp.start, function* () {
|
||||
yield `(`;
|
||||
}), (0, transform_1.insert)(callExp.end, function* () {
|
||||
yield ` as typeof ${names.dollars}.$slots)`;
|
||||
}));
|
||||
}
|
||||
}
|
||||
for (const { callExp, arg } of scriptSetupRanges.useTemplateRef) {
|
||||
transforms.push((0, transform_1.insert)(callExp.start, function* () {
|
||||
yield `(`;
|
||||
}), (0, transform_1.insert)(callExp.end, function* () {
|
||||
yield ` as Readonly<import('${options.vueCompilerOptions.lib}').ShallowRef<`;
|
||||
if (arg) {
|
||||
yield names.TemplateRefs;
|
||||
yield `[`;
|
||||
yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.withoutSemantic);
|
||||
yield `]`;
|
||||
}
|
||||
else {
|
||||
yield `unknown`;
|
||||
}
|
||||
yield ` | null>>)`;
|
||||
}));
|
||||
if (arg) {
|
||||
transforms.push((0, transform_1.replace)(arg.start, arg.end, function* () {
|
||||
yield `{} as any`;
|
||||
}));
|
||||
}
|
||||
}
|
||||
yield* (0, transform_1.generateCodeWithTransforms)(Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset), scriptSetup.content.length, transforms, (start, end) => (0, utils_1.generateSfcBlockSection)(scriptSetup, start, end, codeFeatures_1.codeFeatures.all));
|
||||
yield* generateMacros(options);
|
||||
yield* generateModels(scriptSetup, scriptSetupRanges);
|
||||
yield* generatePublicProps(options, ctx, scriptSetup, scriptSetupRanges);
|
||||
yield* body;
|
||||
if (output) {
|
||||
if (hasSlotsType(options)) {
|
||||
yield `const __VLS_base = `;
|
||||
yield* (0, component_1.generateComponent)(options, ctx, scriptSetup, scriptSetupRanges);
|
||||
yield utils_1.endOfLine;
|
||||
yield* output;
|
||||
yield `{} as ${ctx.localTypes.WithSlots}<typeof __VLS_base, ${names.Slots}>${utils_1.endOfLine}`;
|
||||
}
|
||||
else {
|
||||
yield* output;
|
||||
yield* (0, component_1.generateComponent)(options, ctx, scriptSetup, scriptSetupRanges);
|
||||
yield utils_1.endOfLine;
|
||||
}
|
||||
}
|
||||
}
|
||||
function* generateMacros(options) {
|
||||
if (options.vueCompilerOptions.target >= 3.3) {
|
||||
yield `// @ts-ignore${utils_1.newLine}`;
|
||||
yield `declare const { `;
|
||||
for (const macro of Object.keys(options.vueCompilerOptions.macros)) {
|
||||
if (!options.exposed.has(macro)) {
|
||||
yield `${macro}, `;
|
||||
}
|
||||
}
|
||||
yield `}: typeof import('${options.vueCompilerOptions.lib}')${utils_1.endOfLine}`;
|
||||
}
|
||||
}
|
||||
function* generateDefineWithTypeTransforms(scriptSetup, statement, callExp, typeArg, name, defaultName, typeName) {
|
||||
if (typeArg) {
|
||||
yield (0, transform_1.insert)(statement.start, function* () {
|
||||
yield `type ${typeName} = `;
|
||||
yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.start, typeArg.end, codeFeatures_1.codeFeatures.all);
|
||||
yield utils_1.endOfLine;
|
||||
});
|
||||
yield (0, transform_1.replace)(typeArg.start, typeArg.end, function* () {
|
||||
yield typeName;
|
||||
});
|
||||
}
|
||||
if (!name) {
|
||||
if (statement.start === callExp.start && statement.end === callExp.end) {
|
||||
yield (0, transform_1.insert)(callExp.start, function* () {
|
||||
yield `const ${defaultName} = `;
|
||||
});
|
||||
}
|
||||
else if (typeArg) {
|
||||
yield (0, transform_1.replace)(statement.start, typeArg.start, function* () {
|
||||
yield `const ${defaultName} = `;
|
||||
yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, callExp.start, typeArg.start, codeFeatures_1.codeFeatures.all);
|
||||
});
|
||||
yield (0, transform_1.replace)(typeArg.end, callExp.end, function* () {
|
||||
yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.end, callExp.end, codeFeatures_1.codeFeatures.all);
|
||||
yield utils_1.endOfLine;
|
||||
yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, statement.start, callExp.start, codeFeatures_1.codeFeatures.all);
|
||||
yield defaultName;
|
||||
});
|
||||
}
|
||||
else {
|
||||
yield (0, transform_1.replace)(statement.start, callExp.end, function* () {
|
||||
yield `const ${defaultName} = `;
|
||||
yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, callExp.start, callExp.end, codeFeatures_1.codeFeatures.all);
|
||||
yield utils_1.endOfLine;
|
||||
yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, statement.start, callExp.start, codeFeatures_1.codeFeatures.all);
|
||||
yield defaultName;
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (!utils_1.identifierRegex.test(name)) {
|
||||
yield (0, transform_1.replace)(statement.start, callExp.start, function* () {
|
||||
yield `const ${defaultName} = `;
|
||||
});
|
||||
yield (0, transform_1.insert)(statement.end, function* () {
|
||||
yield utils_1.endOfLine;
|
||||
yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, statement.start, callExp.start, codeFeatures_1.codeFeatures.all);
|
||||
yield defaultName;
|
||||
});
|
||||
}
|
||||
}
|
||||
function* generatePublicProps(options, ctx, scriptSetup, scriptSetupRanges) {
|
||||
if (scriptSetupRanges.defineProps?.typeArg && scriptSetupRanges.withDefaults?.arg) {
|
||||
yield `const ${names.defaults} = `;
|
||||
yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.withDefaults.arg.start, scriptSetupRanges.withDefaults.arg.end, codeFeatures_1.codeFeatures.navigation);
|
||||
yield utils_1.endOfLine;
|
||||
}
|
||||
const propTypes = [];
|
||||
if (options.vueCompilerOptions.jsxSlots && hasSlotsType(options)) {
|
||||
propTypes.push(`${ctx.localTypes.PropsChildren}<${names.Slots}>`);
|
||||
}
|
||||
if (scriptSetupRanges.defineProps?.typeArg) {
|
||||
propTypes.push(names.Props);
|
||||
}
|
||||
if (scriptSetupRanges.defineModel.length) {
|
||||
propTypes.push(names.ModelProps);
|
||||
}
|
||||
if (propTypes.length) {
|
||||
yield `type ${names.PublicProps} = ${propTypes.join(` & `)}${utils_1.endOfLine}`;
|
||||
ctx.generatedTypes.add(names.PublicProps);
|
||||
}
|
||||
}
|
||||
function hasSlotsType(options) {
|
||||
return !!(options.scriptSetupRanges?.defineSlots
|
||||
|| options.templateAndStyleTypes.has(names.Slots));
|
||||
}
|
||||
function* generateModels(scriptSetup, scriptSetupRanges) {
|
||||
if (!scriptSetupRanges.defineModel.length) {
|
||||
return;
|
||||
}
|
||||
const defaultCodes = [];
|
||||
const propCodes = [];
|
||||
const emitCodes = [];
|
||||
for (const defineModel of scriptSetupRanges.defineModel) {
|
||||
const propName = defineModel.name
|
||||
? (0, shared_1.camelize)(getRangeText(scriptSetup, defineModel.name).slice(1, -1))
|
||||
: 'modelValue';
|
||||
let modelType;
|
||||
if (defineModel.type) {
|
||||
// Infer from defineModel<T>
|
||||
modelType = getRangeText(scriptSetup, defineModel.type);
|
||||
}
|
||||
else if (defineModel.runtimeType && defineModel.localName) {
|
||||
// Infer from actual prop declaration code
|
||||
modelType = `typeof ${getRangeText(scriptSetup, defineModel.localName)}['value']`;
|
||||
}
|
||||
else if (defineModel.defaultValue && propName) {
|
||||
// Infer from defineModel({ default: T })
|
||||
modelType = `typeof ${names.defaultModels}['${propName}']`;
|
||||
}
|
||||
else {
|
||||
modelType = `any`;
|
||||
}
|
||||
if (defineModel.defaultValue) {
|
||||
defaultCodes.push(`'${propName}': ${getRangeText(scriptSetup, defineModel.defaultValue)},${utils_1.newLine}`);
|
||||
}
|
||||
propCodes.push(generateModelProp(scriptSetup, defineModel, propName, modelType));
|
||||
emitCodes.push(generateModelEmit(defineModel, propName, modelType));
|
||||
}
|
||||
if (defaultCodes.length) {
|
||||
yield `const ${names.defaultModels} = {${utils_1.newLine}`;
|
||||
yield* defaultCodes;
|
||||
yield `}${utils_1.endOfLine}`;
|
||||
}
|
||||
yield `type ${names.ModelProps} = {${utils_1.newLine}`;
|
||||
for (const codes of propCodes) {
|
||||
yield* codes;
|
||||
}
|
||||
yield `}${utils_1.endOfLine}`;
|
||||
yield `type ${names.ModelEmit} = {${utils_1.newLine}`;
|
||||
for (const codes of emitCodes) {
|
||||
yield* codes;
|
||||
}
|
||||
yield `}${utils_1.endOfLine}`;
|
||||
// avoid `defineModel<...>()` to prevent JS AST issues
|
||||
yield `let ${names.modelEmit}!: __VLS_ShortEmits<${names.ModelEmit}>${utils_1.endOfLine}`;
|
||||
}
|
||||
function* generateModelProp(scriptSetup, defineModel, propName, modelType) {
|
||||
if (defineModel.comments) {
|
||||
yield scriptSetup.content.slice(defineModel.comments.start, defineModel.comments.end);
|
||||
yield utils_1.newLine;
|
||||
}
|
||||
if (defineModel.name) {
|
||||
yield* (0, camelized_1.generateCamelized)(getRangeText(scriptSetup, defineModel.name), scriptSetup.name, defineModel.name.start, codeFeatures_1.codeFeatures.navigation);
|
||||
}
|
||||
else {
|
||||
yield propName;
|
||||
}
|
||||
yield defineModel.required ? `: ` : `?: `;
|
||||
yield modelType;
|
||||
yield utils_1.endOfLine;
|
||||
if (defineModel.modifierType) {
|
||||
const modifierName = `${propName === 'modelValue' ? 'model' : propName}Modifiers`;
|
||||
const modifierType = getRangeText(scriptSetup, defineModel.modifierType);
|
||||
yield `'${modifierName}'?: Partial<Record<${modifierType}, true>>${utils_1.endOfLine}`;
|
||||
}
|
||||
}
|
||||
function* generateModelEmit(defineModel, propName, modelType) {
|
||||
yield `'update:${propName}': [value: `;
|
||||
yield modelType;
|
||||
if (!defineModel.required && !defineModel.defaultValue) {
|
||||
yield ` | undefined`;
|
||||
}
|
||||
yield `]${utils_1.endOfLine}`;
|
||||
}
|
||||
function getRangeText(scriptSetup, range) {
|
||||
return scriptSetup.content.slice(range.start, range.end);
|
||||
}
|
||||
//# sourceMappingURL=scriptSetup.js.map
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import type { Code } from '../../types';
|
||||
import type { ScriptCodegenContext } from './context';
|
||||
import type { ScriptCodegenOptions } from './index';
|
||||
export declare function generateTemplate(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, selfType?: string): Generator<Code>;
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateTemplate = generateTemplate;
|
||||
const codeFeatures_1 = require("../codeFeatures");
|
||||
const names = __importStar(require("../names"));
|
||||
const utils_1 = require("../utils");
|
||||
const merge_1 = require("../utils/merge");
|
||||
function* generateTemplate(options, ctx, selfType) {
|
||||
yield* generateSetupExposed(options, ctx);
|
||||
yield* generateTemplateCtx(options, ctx, selfType);
|
||||
yield* generateTemplateComponents(options, ctx);
|
||||
yield* generateTemplateDirectives(options, ctx);
|
||||
if (options.templateAndStyleCodes.length) {
|
||||
yield* options.templateAndStyleCodes;
|
||||
}
|
||||
}
|
||||
function* generateTemplateCtx({ vueCompilerOptions, templateAndStyleTypes, scriptSetupRanges, fileName }, ctx, selfType) {
|
||||
const exps = [];
|
||||
const emitTypes = [];
|
||||
const propTypes = [];
|
||||
if (vueCompilerOptions.petiteVueExtensions.some(ext => fileName.endsWith(ext))) {
|
||||
exps.push([`globalThis`]);
|
||||
}
|
||||
if (selfType) {
|
||||
exps.push([`{} as InstanceType<__VLS_PickNotAny<typeof ${selfType}, new () => {}>>`]);
|
||||
}
|
||||
else {
|
||||
exps.push([`{} as import('${vueCompilerOptions.lib}').ComponentPublicInstance`]);
|
||||
}
|
||||
if (templateAndStyleTypes.has(names.StyleModules)) {
|
||||
exps.push([`{} as ${names.StyleModules}`]);
|
||||
}
|
||||
if (scriptSetupRanges?.defineEmits) {
|
||||
const { defineEmits } = scriptSetupRanges;
|
||||
emitTypes.push(`typeof ${defineEmits.name ?? names.emit}`);
|
||||
}
|
||||
if (scriptSetupRanges?.defineModel.length) {
|
||||
emitTypes.push(`typeof ${names.modelEmit}`);
|
||||
}
|
||||
if (emitTypes.length) {
|
||||
yield `type ${names.EmitProps} = __VLS_EmitsToProps<__VLS_NormalizeEmits<${emitTypes.join(` & `)}>>${utils_1.endOfLine}`;
|
||||
exps.push([`{} as { $emit: ${emitTypes.join(` & `)} }`]);
|
||||
}
|
||||
if (scriptSetupRanges?.defineProps) {
|
||||
propTypes.push(`typeof ${scriptSetupRanges.defineProps.name ?? names.props}`);
|
||||
}
|
||||
if (scriptSetupRanges?.defineModel.length) {
|
||||
propTypes.push(names.ModelProps);
|
||||
}
|
||||
if (emitTypes.length) {
|
||||
propTypes.push(names.EmitProps);
|
||||
}
|
||||
if (propTypes.length) {
|
||||
exps.push([`{} as { $props: ${propTypes.join(` & `)} }`]);
|
||||
exps.push([`{} as ${propTypes.join(` & `)}`]);
|
||||
}
|
||||
if (ctx.generatedTypes.has(names.SetupExposed)) {
|
||||
exps.push([`{} as ${names.SetupExposed}`]);
|
||||
}
|
||||
yield `const ${names.ctx} = `;
|
||||
yield* (0, merge_1.generateSpreadMerge)(exps);
|
||||
yield utils_1.endOfLine;
|
||||
}
|
||||
function* generateTemplateComponents({ vueCompilerOptions, script, scriptRanges }, ctx) {
|
||||
const types = [];
|
||||
if (ctx.generatedTypes.has(names.SetupExposed)) {
|
||||
types.push(names.SetupExposed);
|
||||
}
|
||||
if (script && scriptRanges?.exportDefault?.options?.components) {
|
||||
const { components } = scriptRanges.exportDefault.options;
|
||||
yield `const __VLS_componentsOption = `;
|
||||
yield* (0, utils_1.generateSfcBlockSection)(script, components.start, components.end, codeFeatures_1.codeFeatures.navigation);
|
||||
yield utils_1.endOfLine;
|
||||
types.push(`typeof __VLS_componentsOption`);
|
||||
}
|
||||
yield `type __VLS_LocalComponents = ${types.length ? types.join(` & `) : `{}`}${utils_1.endOfLine}`;
|
||||
yield `type __VLS_GlobalComponents = ${vueCompilerOptions.target >= 3.5
|
||||
? `import('${vueCompilerOptions.lib}').GlobalComponents`
|
||||
: `import('${vueCompilerOptions.lib}').GlobalComponents & Pick<typeof import('${vueCompilerOptions.lib}'), 'Transition' | 'TransitionGroup' | 'KeepAlive' | 'Suspense' | 'Teleport'>`}${utils_1.endOfLine}`;
|
||||
yield `let ${names.components}!: __VLS_LocalComponents & __VLS_GlobalComponents${utils_1.endOfLine}`;
|
||||
yield `let ${names.intrinsics}!: ${vueCompilerOptions.target >= 3.3
|
||||
? `import('${vueCompilerOptions.lib}/jsx-runtime').JSX.IntrinsicElements`
|
||||
: `globalThis.JSX.IntrinsicElements`}${utils_1.endOfLine}`;
|
||||
}
|
||||
function* generateTemplateDirectives({ vueCompilerOptions, script, scriptRanges }, ctx) {
|
||||
const types = [];
|
||||
if (ctx.generatedTypes.has(names.SetupExposed)) {
|
||||
types.push(names.SetupExposed);
|
||||
}
|
||||
if (script && scriptRanges?.exportDefault?.options?.directives) {
|
||||
const { directives } = scriptRanges.exportDefault.options;
|
||||
yield `const __VLS_directivesOption = `;
|
||||
yield* (0, utils_1.generateSfcBlockSection)(script, directives.start, directives.end, codeFeatures_1.codeFeatures.navigation);
|
||||
yield utils_1.endOfLine;
|
||||
types.push(`__VLS_ResolveDirectives<typeof __VLS_directivesOption>`);
|
||||
}
|
||||
yield `type __VLS_LocalDirectives = ${types.length ? types.join(` & `) : `{}`}${utils_1.endOfLine}`;
|
||||
yield `let ${names.directives}!: __VLS_LocalDirectives & import('${vueCompilerOptions.lib}').GlobalDirectives${utils_1.endOfLine}`;
|
||||
}
|
||||
function* generateSetupExposed({ vueCompilerOptions, exposed }, ctx) {
|
||||
if (!exposed.size) {
|
||||
return;
|
||||
}
|
||||
ctx.generatedTypes.add(names.SetupExposed);
|
||||
yield `type ${names.SetupExposed} = import('${vueCompilerOptions.lib}').ShallowUnwrapRef<{${utils_1.newLine}`;
|
||||
for (const bindingName of exposed) {
|
||||
const token = Symbol(bindingName.length);
|
||||
yield ['', undefined, 0, { __linkedToken: token }];
|
||||
yield `${bindingName}: typeof `;
|
||||
yield ['', undefined, 0, { __linkedToken: token }];
|
||||
yield bindingName;
|
||||
yield utils_1.endOfLine;
|
||||
}
|
||||
yield `}>${utils_1.endOfLine}`;
|
||||
}
|
||||
//# sourceMappingURL=template.js.map
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import type { Code, Sfc } from '../../types';
|
||||
export declare function generateClassProperty(source: string, classNameWithDot: string, offset: number, propertyType: string): Generator<Code>;
|
||||
export declare function generateStyleImports(style: Sfc['styles'][number]): Generator<Code>;
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateClassProperty = generateClassProperty;
|
||||
exports.generateStyleImports = generateStyleImports;
|
||||
const codeFeatures_1 = require("../codeFeatures");
|
||||
const utils_1 = require("../utils");
|
||||
const boundary_1 = require("../utils/boundary");
|
||||
function* generateClassProperty(source, classNameWithDot, offset, propertyType) {
|
||||
yield `${utils_1.newLine} & { `;
|
||||
const token = yield* (0, boundary_1.startBoundary)(source, offset, codeFeatures_1.codeFeatures.navigation);
|
||||
yield `'`;
|
||||
yield [classNameWithDot.slice(1), source, offset + 1, { __combineToken: token }];
|
||||
yield `'`;
|
||||
yield (0, boundary_1.endBoundary)(token, offset + classNameWithDot.length);
|
||||
yield `: ${propertyType}`;
|
||||
yield ` }`;
|
||||
}
|
||||
function* generateStyleImports(style) {
|
||||
const features = {
|
||||
navigation: true,
|
||||
verification: true,
|
||||
};
|
||||
if (typeof style.src === 'object') {
|
||||
yield `${utils_1.newLine} & typeof import(`;
|
||||
const token = yield* (0, boundary_1.startBoundary)('main', style.src.offset, features);
|
||||
yield `'`;
|
||||
yield [style.src.text, 'main', style.src.offset, { __combineToken: token }];
|
||||
yield `'`;
|
||||
yield (0, boundary_1.endBoundary)(token, style.src.offset + style.src.text.length);
|
||||
yield `).default`;
|
||||
}
|
||||
for (const { text, offset } of style.imports) {
|
||||
yield `${utils_1.newLine} & typeof import('`;
|
||||
yield [
|
||||
text,
|
||||
style.name,
|
||||
offset,
|
||||
features,
|
||||
];
|
||||
yield `').default`;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=common.js.map
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
import type { Code, Sfc, VueCompilerOptions } from '../../types';
|
||||
export interface StyleCodegenOptions {
|
||||
typescript: typeof import('typescript');
|
||||
vueCompilerOptions: VueCompilerOptions;
|
||||
styles: Sfc['styles'];
|
||||
setupRefs: Set<string>;
|
||||
setupConsts: Set<string>;
|
||||
}
|
||||
export { generate as generateStyle };
|
||||
declare function generate(options: StyleCodegenOptions): {
|
||||
generatedTypes: Set<string>;
|
||||
currentInfo: {
|
||||
ignoreError?: boolean | undefined;
|
||||
expectError?: {
|
||||
token: number;
|
||||
node: import("@vue/compiler-dom").CommentNode;
|
||||
} | undefined;
|
||||
generic?: {
|
||||
content: string;
|
||||
offset: number;
|
||||
} | undefined;
|
||||
};
|
||||
resolveCodeFeatures: (features: import("../../types").VueCodeInformation) => import("../../types").VueCodeInformation;
|
||||
inVFor: boolean;
|
||||
slots: {
|
||||
name: string;
|
||||
offset?: number | undefined;
|
||||
tagRange: [number, number];
|
||||
nodeLoc: any;
|
||||
propsVar: string;
|
||||
}[];
|
||||
dynamicSlots: {
|
||||
expVar: string;
|
||||
propsVar: string;
|
||||
}[];
|
||||
dollarVars: Set<string>;
|
||||
componentAccessMap: Map<string, Map<string, Set<number>>>;
|
||||
blockConditions: string[];
|
||||
inlayHints: import("../inlayHints").InlayHintInfo[];
|
||||
inheritedAttrVars: Set<string>;
|
||||
templateRefs: Map<string, {
|
||||
typeExp: string;
|
||||
offset: number;
|
||||
}[]>;
|
||||
singleRootElTypes: Set<string>;
|
||||
singleRootNodes: Set<import("@vue/compiler-dom").ElementNode | null>;
|
||||
addTemplateRef(name: string, typeExp: string, offset: number): void;
|
||||
recordComponentAccess(source: string, name: string, offset?: number | undefined): void;
|
||||
scopes: Set<string>[];
|
||||
components: (() => string)[];
|
||||
declare(...varNames: string[]): void;
|
||||
startScope(): () => Generator<Code, any, any>;
|
||||
getInternalVariable(): string;
|
||||
getHoistVariable(originalVar: string): string;
|
||||
generateHoistVariables(): Generator<string, void, unknown>;
|
||||
generateConditionGuards(): Generator<string, void, unknown>;
|
||||
enter(node: import("@vue/compiler-dom").RootNode | import("@vue/compiler-dom").SimpleExpressionNode | import("@vue/compiler-dom").TemplateChildNode): boolean;
|
||||
exit(): Generator<Code, any, any>;
|
||||
codes: Code[];
|
||||
};
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateStyle = generate;
|
||||
const codeFeatures_1 = require("../codeFeatures");
|
||||
const modules_1 = require("../style/modules");
|
||||
const scopedClasses_1 = require("../style/scopedClasses");
|
||||
const context_1 = require("../template/context");
|
||||
const interpolation_1 = require("../template/interpolation");
|
||||
const utils_1 = require("../utils");
|
||||
function generate(options) {
|
||||
const ctx = (0, context_1.createTemplateCodegenContext)();
|
||||
const codeGenerator = generateWorker(options, ctx);
|
||||
const codes = [];
|
||||
for (const code of codeGenerator) {
|
||||
if (typeof code === 'object') {
|
||||
code[3] = ctx.resolveCodeFeatures(code[3]);
|
||||
}
|
||||
codes.push(code);
|
||||
}
|
||||
return { ...ctx, codes };
|
||||
}
|
||||
function* generateWorker(options, ctx) {
|
||||
const endScope = ctx.startScope();
|
||||
ctx.declare(...options.setupConsts);
|
||||
yield* (0, scopedClasses_1.generateStyleScopedClasses)(options);
|
||||
yield* (0, modules_1.generateStyleModules)(options, ctx);
|
||||
yield* generateCssVars(options, ctx);
|
||||
yield* endScope();
|
||||
}
|
||||
function* generateCssVars(options, ctx) {
|
||||
for (const style of options.styles) {
|
||||
for (const binding of style.bindings) {
|
||||
yield* (0, interpolation_1.generateInterpolation)(options, ctx, style, codeFeatures_1.codeFeatures.all, binding.text, binding.offset, `(`, `)`);
|
||||
yield utils_1.endOfLine;
|
||||
}
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=index.js.map
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import type { Code } from '../../types';
|
||||
import type { TemplateCodegenContext } from '../template/context';
|
||||
import type { StyleCodegenOptions } from '.';
|
||||
export declare function generateStyleModules({ styles, vueCompilerOptions }: StyleCodegenOptions, ctx: TemplateCodegenContext): Generator<Code>;
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateStyleModules = generateStyleModules;
|
||||
const codeFeatures_1 = require("../codeFeatures");
|
||||
const names = __importStar(require("../names"));
|
||||
const utils_1 = require("../utils");
|
||||
const common_1 = require("./common");
|
||||
function* generateStyleModules({ styles, vueCompilerOptions }, ctx) {
|
||||
const styleModules = styles.filter(style => style.module);
|
||||
if (!styleModules.length) {
|
||||
return;
|
||||
}
|
||||
ctx.generatedTypes.add(names.StyleModules);
|
||||
yield `type ${names.StyleModules} = {${utils_1.newLine}`;
|
||||
for (const style of styleModules) {
|
||||
if (style.module === true) {
|
||||
yield `$style`;
|
||||
}
|
||||
else {
|
||||
const { text, offset } = style.module;
|
||||
yield [
|
||||
text,
|
||||
'main',
|
||||
offset,
|
||||
codeFeatures_1.codeFeatures.navigation,
|
||||
];
|
||||
}
|
||||
yield `: `;
|
||||
if (!vueCompilerOptions.strictCssModules) {
|
||||
yield `Record<string, string> & `;
|
||||
}
|
||||
yield `__VLS_PrettifyGlobal<{}`;
|
||||
if (vueCompilerOptions.resolveStyleImports) {
|
||||
yield* (0, common_1.generateStyleImports)(style);
|
||||
}
|
||||
for (const className of style.classNames) {
|
||||
yield* (0, common_1.generateClassProperty)(style.name, className.text, className.offset, 'string');
|
||||
}
|
||||
yield `>${utils_1.endOfLine}`;
|
||||
}
|
||||
yield `}${utils_1.endOfLine}`;
|
||||
}
|
||||
//# sourceMappingURL=modules.js.map
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import type { Code } from '../../types';
|
||||
import type { StyleCodegenOptions } from '.';
|
||||
export declare function generateStyleScopedClasses({ vueCompilerOptions, styles }: StyleCodegenOptions): Generator<Code>;
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateStyleScopedClasses = generateStyleScopedClasses;
|
||||
const styleScopedClasses_1 = require("../template/styleScopedClasses");
|
||||
const utils_1 = require("../utils");
|
||||
const common_1 = require("./common");
|
||||
function* generateStyleScopedClasses({ vueCompilerOptions, styles }) {
|
||||
const { resolveStyleClassNames, resolveStyleImports } = vueCompilerOptions;
|
||||
if (!resolveStyleClassNames) {
|
||||
return;
|
||||
}
|
||||
const scopedStyles = styles.filter(style => resolveStyleClassNames === true || style.scoped);
|
||||
if (!scopedStyles.length) {
|
||||
return;
|
||||
}
|
||||
const visited = new Set();
|
||||
const deferredGenerations = [];
|
||||
yield `type __VLS_StyleScopedClasses = {}`;
|
||||
for (const style of scopedStyles) {
|
||||
if (resolveStyleImports) {
|
||||
yield* (0, common_1.generateStyleImports)(style);
|
||||
}
|
||||
for (const className of style.classNames) {
|
||||
if (!visited.has(className.text)) {
|
||||
visited.add(className.text);
|
||||
yield* (0, common_1.generateClassProperty)(style.name, className.text, className.offset, 'boolean');
|
||||
}
|
||||
else {
|
||||
deferredGenerations.push((0, styleScopedClasses_1.generateStyleScopedClassReference)(style, className.text.slice(1), className.offset + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
yield utils_1.endOfLine;
|
||||
for (const generate of deferredGenerations) {
|
||||
yield* generate;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=scopedClasses.js.map
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
import * as CompilerDOM from '@vue/compiler-dom';
|
||||
import type { Code, VueCodeInformation } from '../../types';
|
||||
import type { InlayHintInfo } from '../inlayHints';
|
||||
export type TemplateCodegenContext = ReturnType<typeof createTemplateCodegenContext>;
|
||||
/**
|
||||
* Creates and returns a Context object used for generating type-checkable TS code
|
||||
* from the template section of a .vue file.
|
||||
*
|
||||
* ## Implementation Notes for supporting `@vue-ignore`, `@vue-expect-error`, and `@vue-skip` directives.
|
||||
*
|
||||
* Vue language tooling supports a number of directives for suppressing diagnostics within
|
||||
* Vue templates (https://github.com/vuejs/language-tools/pull/3215)
|
||||
*
|
||||
* Here is an overview for how support for how @vue-expect-error is implemented within this file
|
||||
* (@vue-expect-error is the most complicated directive to support due to its behavior of raising
|
||||
* a diagnostic when it is annotating a piece of code that doesn't actually have any errors/warning/diagnostics).
|
||||
*
|
||||
* Given .vue code:
|
||||
*
|
||||
* ```vue
|
||||
* <script setup lang="ts">
|
||||
* defineProps<{
|
||||
* knownProp1: string;
|
||||
* knownProp2: string;
|
||||
* knownProp3: string;
|
||||
* knownProp4_will_trigger_unused_expect_error: string;
|
||||
* }>();
|
||||
* </script>
|
||||
*
|
||||
* <template>
|
||||
* {{ knownProp1 }}
|
||||
* {{ error_unknownProp }} <!-- ERROR: Property 'error_unknownProp' does not exist on type [...] -->
|
||||
* {{ knownProp2 }}
|
||||
* <!-- @vue-expect-error This suppresses an Unknown Property Error -->
|
||||
* {{ suppressed_error_unknownProp }}
|
||||
* {{ knownProp3 }}
|
||||
* <!-- @vue-expect-error This will trigger Unused '@ts-expect-error' directive.ts(2578) -->
|
||||
* {{ knownProp4_will_trigger_unused_expect_error }}
|
||||
* </template>
|
||||
* ```
|
||||
*
|
||||
* The above code should raise two diagnostics:
|
||||
*
|
||||
* 1. Property 'error_unknownProp' does not exist on type [...]
|
||||
* 2. Unused '@ts-expect-error' directive.ts(2578) -- this is the bottom `@vue-expect-error` directive
|
||||
* that covers code that doesn't actually raise an error -- note that all `@vue-...` directives
|
||||
* will ultimately translate into `@ts-...` diagnostics.
|
||||
*
|
||||
* The above code will produce the following type-checkable TS code (note: omitting asterisks
|
||||
* to prevent VSCode syntax double-greying out double-commented code).
|
||||
*
|
||||
* ```ts
|
||||
* ( __VLS_ctx.knownProp1 );
|
||||
* ( __VLS_ctx.error_unknownProp ); // ERROR: Property 'error_unknownProp' does not exist on type [...]
|
||||
* ( __VLS_ctx.knownProp2 );
|
||||
* // @vue-expect-error start
|
||||
* ( __VLS_ctx.suppressed_error_unknownProp );
|
||||
* // @ts-expect-error __VLS_TS_EXPECT_ERROR
|
||||
* ;
|
||||
* // @vue-expect-error end of INTERPOLATION
|
||||
* ( __VLS_ctx.knownProp3 );
|
||||
* // @vue-expect-error start
|
||||
* ( __VLS_ctx.knownProp4_will_trigger_unused_expect_error );
|
||||
* // @ts-expect-error __VLS_TS_EXPECT_ERROR
|
||||
* ;
|
||||
* // @vue-expect-error end of INTERPOLATION
|
||||
* ```
|
||||
*
|
||||
* In the generated code, there are actually 3 diagnostic errors that'll be raised in the first
|
||||
* pass on this generated code (but through cleverness described below, not all of them will be
|
||||
* propagated back to the original .vue file):
|
||||
*
|
||||
* 1. Property 'error_unknownProp' does not exist on type [...]
|
||||
* 2. Unused '@ts-expect-error' directive.ts(2578) from the 1st `@ts-expect-error __VLS_TS_EXPECT_ERROR`
|
||||
* 3. Unused '@ts-expect-error' directive.ts(2578) from the 2nd `@ts-expect-error __VLS_TS_EXPECT_ERROR`
|
||||
*
|
||||
* Be sure to pay careful attention to the mixture of `@vue-expect-error` and `@ts-expect-error`;
|
||||
* Within the TS file, the only "real" directives recognized by TS are going to be prefixed with `@ts-`;
|
||||
* any `@vue-` prefixed directives in the comments are only for debugging purposes.
|
||||
*
|
||||
* As mentioned above, there are 3 diagnostics errors that'll be generated for the above code, but
|
||||
* only 2 should be propagated back to the original .vue file.
|
||||
*
|
||||
* (The reason we structure things this way is somewhat complicated, but in short it allows us
|
||||
* to lean on TS as much as possible to generate actual `unused @ts-expect-error directive` errors
|
||||
* while covering a number of edge cases.)
|
||||
*
|
||||
* So, we need a way to dynamically decide whether each of the `@ts-expect-error __VLS_TS_EXPECT_ERROR`
|
||||
* directives should be reported as an unused directive or not.
|
||||
*
|
||||
* To do this, we'll make use of the `shouldReport` callback that'll optionally be provided to the
|
||||
* `verification` property of the `CodeInformation` object attached to the mapping between source .vue
|
||||
* and generated .ts code. The `verification` property determines whether "verification" (which includes
|
||||
* semantic diagnostics) should be performed on the generated .ts code, and `shouldReport`, if provided,
|
||||
* can be used to determine whether a given diagnostic should be reported back "upwards" to the original
|
||||
* .vue file or not.
|
||||
*
|
||||
* See the comments in the code below for how and where we use this hook to keep track of whether
|
||||
* an error/diagnostic was encountered for a region of code covered by a `@vue-expect-error` directive,
|
||||
* and additionally how we use that to determine whether to propagate diagnostics back upward.
|
||||
*/
|
||||
export declare function createTemplateCodegenContext(): {
|
||||
generatedTypes: Set<string>;
|
||||
readonly currentInfo: {
|
||||
ignoreError?: boolean | undefined;
|
||||
expectError?: {
|
||||
token: number;
|
||||
node: CompilerDOM.CommentNode;
|
||||
} | undefined;
|
||||
generic?: {
|
||||
content: string;
|
||||
offset: number;
|
||||
} | undefined;
|
||||
};
|
||||
resolveCodeFeatures: (features: VueCodeInformation) => VueCodeInformation;
|
||||
inVFor: boolean;
|
||||
slots: {
|
||||
name: string;
|
||||
offset?: number | undefined;
|
||||
tagRange: [number, number];
|
||||
nodeLoc: any;
|
||||
propsVar: string;
|
||||
}[];
|
||||
dynamicSlots: {
|
||||
expVar: string;
|
||||
propsVar: string;
|
||||
}[];
|
||||
dollarVars: Set<string>;
|
||||
componentAccessMap: Map<string, Map<string, Set<number>>>;
|
||||
blockConditions: string[];
|
||||
inlayHints: InlayHintInfo[];
|
||||
inheritedAttrVars: Set<string>;
|
||||
templateRefs: Map<string, {
|
||||
typeExp: string;
|
||||
offset: number;
|
||||
}[]>;
|
||||
singleRootElTypes: Set<string>;
|
||||
singleRootNodes: Set<CompilerDOM.ElementNode | null>;
|
||||
addTemplateRef(name: string, typeExp: string, offset: number): void;
|
||||
recordComponentAccess(source: string, name: string, offset?: number | undefined): void;
|
||||
scopes: Set<string>[];
|
||||
components: (() => string)[];
|
||||
declare(...varNames: string[]): void;
|
||||
startScope(): () => Generator<Code, any, any>;
|
||||
getInternalVariable(): string;
|
||||
getHoistVariable(originalVar: string): string;
|
||||
generateHoistVariables(): Generator<string, void, unknown>;
|
||||
generateConditionGuards(): Generator<string, void, unknown>;
|
||||
enter(node: CompilerDOM.RootNode | CompilerDOM.SimpleExpressionNode | CompilerDOM.TemplateChildNode): boolean;
|
||||
exit(): Generator<Code, any, any>;
|
||||
};
|
||||
+346
@@ -0,0 +1,346 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createTemplateCodegenContext = createTemplateCodegenContext;
|
||||
const CompilerDOM = __importStar(require("@vue/compiler-dom"));
|
||||
const codeFeatures_1 = require("../codeFeatures");
|
||||
const utils_1 = require("../utils");
|
||||
const boundary_1 = require("../utils/boundary");
|
||||
const commentDirectiveRegex = /^<!--\s*@vue-(?<name>[-\w]+)\b(?<content>[\s\S]*)-->$/;
|
||||
/**
|
||||
* Creates and returns a Context object used for generating type-checkable TS code
|
||||
* from the template section of a .vue file.
|
||||
*
|
||||
* ## Implementation Notes for supporting `@vue-ignore`, `@vue-expect-error`, and `@vue-skip` directives.
|
||||
*
|
||||
* Vue language tooling supports a number of directives for suppressing diagnostics within
|
||||
* Vue templates (https://github.com/vuejs/language-tools/pull/3215)
|
||||
*
|
||||
* Here is an overview for how support for how @vue-expect-error is implemented within this file
|
||||
* (@vue-expect-error is the most complicated directive to support due to its behavior of raising
|
||||
* a diagnostic when it is annotating a piece of code that doesn't actually have any errors/warning/diagnostics).
|
||||
*
|
||||
* Given .vue code:
|
||||
*
|
||||
* ```vue
|
||||
* <script setup lang="ts">
|
||||
* defineProps<{
|
||||
* knownProp1: string;
|
||||
* knownProp2: string;
|
||||
* knownProp3: string;
|
||||
* knownProp4_will_trigger_unused_expect_error: string;
|
||||
* }>();
|
||||
* </script>
|
||||
*
|
||||
* <template>
|
||||
* {{ knownProp1 }}
|
||||
* {{ error_unknownProp }} <!-- ERROR: Property 'error_unknownProp' does not exist on type [...] -->
|
||||
* {{ knownProp2 }}
|
||||
* <!-- @vue-expect-error This suppresses an Unknown Property Error -->
|
||||
* {{ suppressed_error_unknownProp }}
|
||||
* {{ knownProp3 }}
|
||||
* <!-- @vue-expect-error This will trigger Unused '@ts-expect-error' directive.ts(2578) -->
|
||||
* {{ knownProp4_will_trigger_unused_expect_error }}
|
||||
* </template>
|
||||
* ```
|
||||
*
|
||||
* The above code should raise two diagnostics:
|
||||
*
|
||||
* 1. Property 'error_unknownProp' does not exist on type [...]
|
||||
* 2. Unused '@ts-expect-error' directive.ts(2578) -- this is the bottom `@vue-expect-error` directive
|
||||
* that covers code that doesn't actually raise an error -- note that all `@vue-...` directives
|
||||
* will ultimately translate into `@ts-...` diagnostics.
|
||||
*
|
||||
* The above code will produce the following type-checkable TS code (note: omitting asterisks
|
||||
* to prevent VSCode syntax double-greying out double-commented code).
|
||||
*
|
||||
* ```ts
|
||||
* ( __VLS_ctx.knownProp1 );
|
||||
* ( __VLS_ctx.error_unknownProp ); // ERROR: Property 'error_unknownProp' does not exist on type [...]
|
||||
* ( __VLS_ctx.knownProp2 );
|
||||
* // @vue-expect-error start
|
||||
* ( __VLS_ctx.suppressed_error_unknownProp );
|
||||
* // @ts-expect-error __VLS_TS_EXPECT_ERROR
|
||||
* ;
|
||||
* // @vue-expect-error end of INTERPOLATION
|
||||
* ( __VLS_ctx.knownProp3 );
|
||||
* // @vue-expect-error start
|
||||
* ( __VLS_ctx.knownProp4_will_trigger_unused_expect_error );
|
||||
* // @ts-expect-error __VLS_TS_EXPECT_ERROR
|
||||
* ;
|
||||
* // @vue-expect-error end of INTERPOLATION
|
||||
* ```
|
||||
*
|
||||
* In the generated code, there are actually 3 diagnostic errors that'll be raised in the first
|
||||
* pass on this generated code (but through cleverness described below, not all of them will be
|
||||
* propagated back to the original .vue file):
|
||||
*
|
||||
* 1. Property 'error_unknownProp' does not exist on type [...]
|
||||
* 2. Unused '@ts-expect-error' directive.ts(2578) from the 1st `@ts-expect-error __VLS_TS_EXPECT_ERROR`
|
||||
* 3. Unused '@ts-expect-error' directive.ts(2578) from the 2nd `@ts-expect-error __VLS_TS_EXPECT_ERROR`
|
||||
*
|
||||
* Be sure to pay careful attention to the mixture of `@vue-expect-error` and `@ts-expect-error`;
|
||||
* Within the TS file, the only "real" directives recognized by TS are going to be prefixed with `@ts-`;
|
||||
* any `@vue-` prefixed directives in the comments are only for debugging purposes.
|
||||
*
|
||||
* As mentioned above, there are 3 diagnostics errors that'll be generated for the above code, but
|
||||
* only 2 should be propagated back to the original .vue file.
|
||||
*
|
||||
* (The reason we structure things this way is somewhat complicated, but in short it allows us
|
||||
* to lean on TS as much as possible to generate actual `unused @ts-expect-error directive` errors
|
||||
* while covering a number of edge cases.)
|
||||
*
|
||||
* So, we need a way to dynamically decide whether each of the `@ts-expect-error __VLS_TS_EXPECT_ERROR`
|
||||
* directives should be reported as an unused directive or not.
|
||||
*
|
||||
* To do this, we'll make use of the `shouldReport` callback that'll optionally be provided to the
|
||||
* `verification` property of the `CodeInformation` object attached to the mapping between source .vue
|
||||
* and generated .ts code. The `verification` property determines whether "verification" (which includes
|
||||
* semantic diagnostics) should be performed on the generated .ts code, and `shouldReport`, if provided,
|
||||
* can be used to determine whether a given diagnostic should be reported back "upwards" to the original
|
||||
* .vue file or not.
|
||||
*
|
||||
* See the comments in the code below for how and where we use this hook to keep track of whether
|
||||
* an error/diagnostic was encountered for a region of code covered by a `@vue-expect-error` directive,
|
||||
* and additionally how we use that to determine whether to propagate diagnostics back upward.
|
||||
*/
|
||||
function createTemplateCodegenContext() {
|
||||
let variableId = 0;
|
||||
const scopes = [];
|
||||
const components = [];
|
||||
const hoistVars = new Map();
|
||||
const dollarVars = new Set();
|
||||
const componentAccessMap = new Map();
|
||||
const slots = [];
|
||||
const dynamicSlots = [];
|
||||
const blockConditions = [];
|
||||
const inlayHints = [];
|
||||
const inheritedAttrVars = new Set();
|
||||
const templateRefs = new Map();
|
||||
const stack = [];
|
||||
const commentBuffer = [];
|
||||
return {
|
||||
generatedTypes: new Set(),
|
||||
get currentInfo() {
|
||||
return stack[stack.length - 1];
|
||||
},
|
||||
resolveCodeFeatures,
|
||||
inVFor: false,
|
||||
slots,
|
||||
dynamicSlots,
|
||||
dollarVars,
|
||||
componentAccessMap,
|
||||
blockConditions,
|
||||
inlayHints,
|
||||
inheritedAttrVars,
|
||||
templateRefs,
|
||||
singleRootElTypes: new Set(),
|
||||
singleRootNodes: new Set(),
|
||||
addTemplateRef(name, typeExp, offset) {
|
||||
let refs = templateRefs.get(name);
|
||||
if (!refs) {
|
||||
templateRefs.set(name, refs = []);
|
||||
}
|
||||
refs.push({ typeExp, offset });
|
||||
},
|
||||
recordComponentAccess(source, name, offset) {
|
||||
let map = componentAccessMap.get(name);
|
||||
if (!map) {
|
||||
componentAccessMap.set(name, map = new Map());
|
||||
}
|
||||
let arr = map.get(source);
|
||||
if (!arr) {
|
||||
map.set(source, arr = new Set());
|
||||
}
|
||||
if (offset !== undefined) {
|
||||
arr.add(offset);
|
||||
}
|
||||
},
|
||||
scopes,
|
||||
components,
|
||||
declare(...varNames) {
|
||||
const scope = scopes.at(-1);
|
||||
for (const varName of varNames) {
|
||||
scope.add(varName);
|
||||
}
|
||||
},
|
||||
startScope() {
|
||||
const scope = new Set();
|
||||
scopes.push(scope);
|
||||
return () => {
|
||||
scopes.pop();
|
||||
return generateAutoImport();
|
||||
};
|
||||
},
|
||||
getInternalVariable() {
|
||||
return `__VLS_${variableId++}`;
|
||||
},
|
||||
getHoistVariable(originalVar) {
|
||||
let name = hoistVars.get(originalVar);
|
||||
if (name === undefined) {
|
||||
hoistVars.set(originalVar, name = `__VLS_${variableId++}`);
|
||||
}
|
||||
return name;
|
||||
},
|
||||
*generateHoistVariables() {
|
||||
// trick to avoid TS 4081 (#5186)
|
||||
if (hoistVars.size) {
|
||||
yield `// @ts-ignore${utils_1.newLine}`;
|
||||
yield `var `;
|
||||
for (const [originalVar, hoistVar] of hoistVars) {
|
||||
yield `${hoistVar} = ${originalVar}, `;
|
||||
}
|
||||
yield utils_1.endOfLine;
|
||||
}
|
||||
},
|
||||
*generateConditionGuards() {
|
||||
for (const condition of blockConditions) {
|
||||
yield `if (!${condition}) return${utils_1.endOfLine}`;
|
||||
}
|
||||
},
|
||||
enter(node) {
|
||||
if (node.type === CompilerDOM.NodeTypes.COMMENT) {
|
||||
commentBuffer.push(node);
|
||||
return false;
|
||||
}
|
||||
const data = {};
|
||||
const comments = [...commentBuffer];
|
||||
commentBuffer.length = 0;
|
||||
for (const comment of comments) {
|
||||
const match = comment.loc.source.match(commentDirectiveRegex);
|
||||
if (match) {
|
||||
const { name, content } = match.groups;
|
||||
switch (name) {
|
||||
case 'skip': {
|
||||
return false;
|
||||
}
|
||||
case 'ignore': {
|
||||
data.ignoreError = true;
|
||||
break;
|
||||
}
|
||||
case 'expect-error': {
|
||||
data.expectError = {
|
||||
token: 0,
|
||||
node: comment,
|
||||
};
|
||||
break;
|
||||
}
|
||||
case 'generic': {
|
||||
const text = content.trim();
|
||||
if (text.startsWith('{') && text.endsWith('}')) {
|
||||
data.generic = {
|
||||
content: text.slice(1, -1),
|
||||
offset: comment.loc.start.offset + comment.loc.source.indexOf('{') + 1,
|
||||
};
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
stack.push(data);
|
||||
return true;
|
||||
},
|
||||
*exit() {
|
||||
const data = stack.pop();
|
||||
commentBuffer.length = 0;
|
||||
if (data.expectError !== undefined) {
|
||||
const token = yield* (0, boundary_1.startBoundary)('template', data.expectError.node.loc.start.offset, {
|
||||
verification: {
|
||||
// If no errors/warnings/diagnostics were reported within the region of code covered
|
||||
// by the @vue-expect-error directive, then we should allow any `unused @ts-expect-error`
|
||||
// diagnostics to be reported upward.
|
||||
shouldReport: () => data.expectError.token === 0,
|
||||
},
|
||||
});
|
||||
yield `// @ts-expect-error`;
|
||||
yield (0, boundary_1.endBoundary)(token, data.expectError.node.loc.end.offset);
|
||||
yield `${utils_1.newLine}${utils_1.endOfLine}`;
|
||||
}
|
||||
},
|
||||
};
|
||||
function* generateAutoImport() {
|
||||
const all = [...componentAccessMap.entries()];
|
||||
if (!all.some(([, offsets]) => offsets.size)) {
|
||||
return;
|
||||
}
|
||||
yield `// @ts-ignore${utils_1.newLine}`; // #2304
|
||||
yield `[`;
|
||||
for (const [varName, map] of all) {
|
||||
for (const [source, offsets] of map) {
|
||||
for (const offset of offsets) {
|
||||
yield [varName, source, offset, codeFeatures_1.codeFeatures.importCompletionOnly];
|
||||
yield `,`;
|
||||
}
|
||||
offsets.clear();
|
||||
}
|
||||
}
|
||||
yield `]${utils_1.endOfLine}`;
|
||||
}
|
||||
function resolveCodeFeatures(features) {
|
||||
if (features.verification && stack.length) {
|
||||
const data = stack[stack.length - 1];
|
||||
if (data.ignoreError) {
|
||||
// We are currently in a region of code covered by a @vue-ignore directive, so don't
|
||||
// even bother performing any type-checking: set verification to false.
|
||||
return {
|
||||
...features,
|
||||
verification: false,
|
||||
};
|
||||
}
|
||||
if (data.expectError !== undefined) {
|
||||
// We are currently in a region of code covered by a @vue-expect-error directive. We need to
|
||||
// keep track of the number of errors encountered within this region so that we can know whether
|
||||
// we will need to propagate an "unused ts-expect-error" diagnostic back to the original
|
||||
// .vue file or not.
|
||||
return {
|
||||
...features,
|
||||
verification: {
|
||||
shouldReport: (source, code) => {
|
||||
if (typeof features.verification !== 'object'
|
||||
|| !features.verification.shouldReport
|
||||
|| features.verification.shouldReport(source, code) === true) {
|
||||
data.expectError.token++;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
return features;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=context.js.map
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
import * as CompilerDOM from '@vue/compiler-dom';
|
||||
import type { Code } from '../../types';
|
||||
import type { TemplateCodegenContext } from './context';
|
||||
import type { TemplateCodegenOptions } from './index';
|
||||
export declare function generateComponent(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode): Generator<Code>;
|
||||
export declare function generateElement(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode): Generator<Code>;
|
||||
+375
@@ -0,0 +1,375 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateComponent = generateComponent;
|
||||
exports.generateElement = generateElement;
|
||||
const CompilerDOM = __importStar(require("@vue/compiler-dom"));
|
||||
const shared_1 = require("@vue/shared");
|
||||
const muggle_string_1 = require("muggle-string");
|
||||
const shared_2 = require("../../utils/shared");
|
||||
const codeFeatures_1 = require("../codeFeatures");
|
||||
const inlayHints_1 = require("../inlayHints");
|
||||
const names = __importStar(require("../names"));
|
||||
const utils_1 = require("../utils");
|
||||
const boundary_1 = require("../utils/boundary");
|
||||
const camelized_1 = require("../utils/camelized");
|
||||
const stringLiteralKey_1 = require("../utils/stringLiteralKey");
|
||||
const elementDirectives_1 = require("./elementDirectives");
|
||||
const elementEvents_1 = require("./elementEvents");
|
||||
const elementProps_1 = require("./elementProps");
|
||||
const interpolation_1 = require("./interpolation");
|
||||
const propertyAccess_1 = require("./propertyAccess");
|
||||
const styleScopedClasses_1 = require("./styleScopedClasses");
|
||||
const templateChild_1 = require("./templateChild");
|
||||
const vSlot_1 = require("./vSlot");
|
||||
function* generateComponent(options, ctx, node) {
|
||||
let { tag, props } = node;
|
||||
let [startTagOffset, endTagOffset] = (0, shared_2.getElementTagOffsets)(node, options.template);
|
||||
let isExpression = false;
|
||||
let isIsShorthand = false;
|
||||
if (tag.includes('.')) {
|
||||
isExpression = true;
|
||||
}
|
||||
else if (tag === 'component') {
|
||||
for (const prop of node.props) {
|
||||
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
||||
&& prop.name === 'bind'
|
||||
&& prop.arg?.loc.source === 'is'
|
||||
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
||||
isIsShorthand = prop.arg.loc.end.offset === prop.exp.loc.end.offset;
|
||||
if (isIsShorthand) {
|
||||
ctx.inlayHints.push((0, inlayHints_1.createVBindShorthandInlayHintInfo)(prop.exp.loc, 'is'));
|
||||
}
|
||||
isExpression = true;
|
||||
tag = prop.exp.content;
|
||||
startTagOffset = prop.exp.loc.start.offset;
|
||||
endTagOffset = undefined;
|
||||
props = props.filter(p => p !== prop);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
const componentVar = ctx.getInternalVariable();
|
||||
if (isExpression) {
|
||||
yield `const ${componentVar} = `;
|
||||
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, isIsShorthand
|
||||
? codeFeatures_1.codeFeatures.withoutHighlightAndCompletion
|
||||
: codeFeatures_1.codeFeatures.all, tag, startTagOffset, `(`, `)`);
|
||||
if (endTagOffset !== undefined) {
|
||||
yield ` || `;
|
||||
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.withoutCompletion, tag, endTagOffset, `(`, `)`);
|
||||
}
|
||||
yield `${utils_1.endOfLine}`;
|
||||
}
|
||||
else {
|
||||
const originalNames = new Set([
|
||||
(0, shared_1.capitalize)((0, shared_1.camelize)(tag)),
|
||||
(0, shared_1.camelize)(tag),
|
||||
tag,
|
||||
]);
|
||||
const matchedSetupConst = [...originalNames].find(name => options.setupConsts.has(name));
|
||||
if (matchedSetupConst) {
|
||||
// navigation & auto import support
|
||||
yield `const ${componentVar} = `;
|
||||
yield* (0, camelized_1.generateCamelized)(matchedSetupConst[0] + tag.slice(1), 'template', startTagOffset, {
|
||||
...codeFeatures_1.codeFeatures.withoutHighlightAndCompletion,
|
||||
...codeFeatures_1.codeFeatures.importCompletionOnly,
|
||||
});
|
||||
if (endTagOffset !== undefined) {
|
||||
yield ` || `;
|
||||
yield* (0, camelized_1.generateCamelized)(matchedSetupConst[0] + tag.slice(1), 'template', endTagOffset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
|
||||
}
|
||||
yield utils_1.endOfLine;
|
||||
}
|
||||
else {
|
||||
yield `let ${componentVar}!: __VLS_WithComponent<'${tag}', __VLS_LocalComponents, __VLS_GlobalComponents`;
|
||||
yield originalNames.has(options.componentName)
|
||||
? `, typeof ${names._export}`
|
||||
: `, void`;
|
||||
for (const name of originalNames) {
|
||||
yield `, '${name}'`;
|
||||
}
|
||||
yield `>[`;
|
||||
yield* (0, stringLiteralKey_1.generateStringLiteralKey)(tag, startTagOffset, {
|
||||
...codeFeatures_1.codeFeatures.semanticWithoutHighlight,
|
||||
...options.vueCompilerOptions.checkUnknownComponents
|
||||
? codeFeatures_1.codeFeatures.verification
|
||||
: codeFeatures_1.codeFeatures.doNotReportTs2339AndTs2551,
|
||||
});
|
||||
yield `]${utils_1.endOfLine}`;
|
||||
if (utils_1.identifierRegex.test((0, shared_1.camelize)(tag))) {
|
||||
// navigation support
|
||||
yield `/** @ts-ignore @type {typeof ${names.components}.`;
|
||||
yield* (0, camelized_1.generateCamelized)(tag, 'template', startTagOffset, codeFeatures_1.codeFeatures.navigation);
|
||||
if (tag[0] !== tag[0].toUpperCase()) {
|
||||
yield ` | typeof ${names.components}.`;
|
||||
yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(tag), 'template', startTagOffset, codeFeatures_1.codeFeatures.navigation);
|
||||
}
|
||||
if (endTagOffset !== undefined) {
|
||||
yield ` | typeof ${names.components}.`;
|
||||
yield* (0, camelized_1.generateCamelized)(tag, 'template', endTagOffset, codeFeatures_1.codeFeatures.navigation);
|
||||
if (tag[0] !== tag[0].toUpperCase()) {
|
||||
yield ` | typeof ${names.components}.`;
|
||||
yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(tag), 'template', endTagOffset, codeFeatures_1.codeFeatures.navigation);
|
||||
}
|
||||
}
|
||||
yield `} */${utils_1.newLine}`;
|
||||
// auto import support
|
||||
yield* (0, camelized_1.generateCamelized)(tag, 'template', startTagOffset, codeFeatures_1.codeFeatures.importCompletionOnly);
|
||||
yield utils_1.endOfLine;
|
||||
}
|
||||
}
|
||||
}
|
||||
yield* generateComponentBody(options, ctx, node, tag, startTagOffset, props, componentVar);
|
||||
}
|
||||
function* generateComponentBody(options, ctx, node, tag, tagOffset, props, componentVar) {
|
||||
let isCtxVarUsed = false;
|
||||
let isPropsVarUsed = false;
|
||||
const getCtxVar = () => (isCtxVarUsed = true, ctxVar);
|
||||
const getPropsVar = () => (isPropsVarUsed = true, propsVar);
|
||||
ctx.components.push(getCtxVar);
|
||||
const failGeneratedExpressions = [];
|
||||
const propCodes = [...(0, elementProps_1.generateElementProps)(options, ctx, node, props, options.vueCompilerOptions.checkUnknownProps, failGeneratedExpressions)];
|
||||
const functionalVar = ctx.getInternalVariable();
|
||||
const vNodeVar = ctx.getInternalVariable();
|
||||
const ctxVar = ctx.getInternalVariable();
|
||||
const propsVar = ctx.getInternalVariable();
|
||||
yield `// @ts-ignore${utils_1.newLine}`;
|
||||
yield `const ${functionalVar} = ${options.vueCompilerOptions.checkUnknownProps ? '__VLS_asFunctionalComponent0' : '__VLS_asFunctionalComponent1'}(${componentVar}, new ${componentVar}({${utils_1.newLine}`;
|
||||
yield (0, muggle_string_1.toString)(propCodes);
|
||||
yield `}))${utils_1.endOfLine}`;
|
||||
yield `const `;
|
||||
const token = yield* (0, boundary_1.startBoundary)('template', node.loc.start.offset, codeFeatures_1.codeFeatures.doNotReportTs6133);
|
||||
yield vNodeVar;
|
||||
yield (0, boundary_1.endBoundary)(token, node.loc.end.offset);
|
||||
yield ` = ${functionalVar}`;
|
||||
if (ctx.currentInfo.generic) {
|
||||
const { content, offset } = ctx.currentInfo.generic;
|
||||
const token = yield* (0, boundary_1.startBoundary)('template', offset, codeFeatures_1.codeFeatures.verification);
|
||||
yield `<`;
|
||||
yield [content, 'template', offset, codeFeatures_1.codeFeatures.all];
|
||||
yield `>`;
|
||||
yield (0, boundary_1.endBoundary)(token, offset + content.length);
|
||||
}
|
||||
yield `(`;
|
||||
const token2 = yield* (0, boundary_1.startBoundary)('template', tagOffset, codeFeatures_1.codeFeatures.verification);
|
||||
yield `{${utils_1.newLine}`;
|
||||
yield* propCodes;
|
||||
yield `}`;
|
||||
yield (0, boundary_1.endBoundary)(token2, tagOffset + tag.length);
|
||||
yield `, ...__VLS_functionalComponentArgsRest(${functionalVar}))${utils_1.endOfLine}`;
|
||||
yield* generateFailedExpressions(options, ctx, failGeneratedExpressions);
|
||||
yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, componentVar, getCtxVar, getPropsVar);
|
||||
yield* (0, elementDirectives_1.generateElementDirectives)(options, ctx, node);
|
||||
const templateRef = getTemplateRef(node);
|
||||
const isRootNode = ctx.singleRootNodes.has(node)
|
||||
&& !options.vueCompilerOptions.fallthroughComponentNames.includes((0, shared_2.hyphenateTag)(tag));
|
||||
if (templateRef || isRootNode) {
|
||||
const componentInstanceVar = ctx.getInternalVariable();
|
||||
yield `var ${componentInstanceVar} = {} as (Parameters<NonNullable<typeof ${getCtxVar()}['expose']>>[0] | null)`;
|
||||
if (ctx.inVFor) {
|
||||
yield `[]`;
|
||||
}
|
||||
yield utils_1.endOfLine;
|
||||
if (templateRef) {
|
||||
const typeExp = `typeof ${ctx.getHoistVariable(componentInstanceVar)}`;
|
||||
ctx.addTemplateRef(templateRef[0], typeExp, templateRef[1]);
|
||||
}
|
||||
if (isRootNode) {
|
||||
ctx.singleRootElTypes.add(`NonNullable<typeof ${componentInstanceVar}>['$el']`);
|
||||
}
|
||||
}
|
||||
if (hasVBindAttrs(options, ctx, node)) {
|
||||
ctx.inheritedAttrVars.add(getPropsVar());
|
||||
}
|
||||
yield* generateStyleScopedClassReferences(options, node);
|
||||
const slotDir = node.props.find(p => p.type === CompilerDOM.NodeTypes.DIRECTIVE && p.name === 'slot');
|
||||
if (slotDir || node.children.length) {
|
||||
yield* (0, vSlot_1.generateVSlot)(options, ctx, node, slotDir, getCtxVar());
|
||||
}
|
||||
if (isCtxVarUsed) {
|
||||
yield `var ${ctxVar}!: __VLS_FunctionalComponentCtx<typeof ${componentVar}, typeof ${vNodeVar}>${utils_1.endOfLine}`;
|
||||
}
|
||||
if (isPropsVarUsed) {
|
||||
yield `var ${propsVar}!: __VLS_FunctionalComponentProps<typeof ${componentVar}, typeof ${vNodeVar}>${utils_1.endOfLine}`;
|
||||
}
|
||||
ctx.components.pop();
|
||||
}
|
||||
function* generateElement(options, ctx, node) {
|
||||
const [startTagOffset, endTagOffset] = (0, shared_2.getElementTagOffsets)(node, options.template);
|
||||
const failedPropExps = [];
|
||||
yield `${options.vueCompilerOptions.checkUnknownProps ? `__VLS_asFunctionalElement0` : `__VLS_asFunctionalElement1`}(${names.intrinsics}`;
|
||||
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, startTagOffset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
|
||||
if (endTagOffset !== undefined) {
|
||||
yield `, `;
|
||||
yield names.intrinsics;
|
||||
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, endTagOffset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
|
||||
}
|
||||
yield `)(`;
|
||||
const token = yield* (0, boundary_1.startBoundary)('template', startTagOffset, codeFeatures_1.codeFeatures.verification);
|
||||
yield `{${utils_1.newLine}`;
|
||||
yield* (0, elementProps_1.generateElementProps)(options, ctx, node, node.props, options.vueCompilerOptions.checkUnknownProps, failedPropExps);
|
||||
yield `}`;
|
||||
yield (0, boundary_1.endBoundary)(token, startTagOffset + node.tag.length);
|
||||
yield `)${utils_1.endOfLine}`;
|
||||
yield* generateFailedExpressions(options, ctx, failedPropExps);
|
||||
yield* (0, elementDirectives_1.generateElementDirectives)(options, ctx, node);
|
||||
const templateRef = getTemplateRef(node);
|
||||
if (templateRef) {
|
||||
let typeExp = `__VLS_Elements['${node.tag}']`;
|
||||
if (ctx.inVFor) {
|
||||
typeExp += `[]`;
|
||||
}
|
||||
ctx.addTemplateRef(templateRef[0], typeExp, templateRef[1]);
|
||||
}
|
||||
if (ctx.singleRootNodes.has(node)) {
|
||||
ctx.singleRootElTypes.add(`__VLS_Elements['${node.tag}']`);
|
||||
}
|
||||
if (hasVBindAttrs(options, ctx, node)) {
|
||||
ctx.inheritedAttrVars.add(`__VLS_intrinsics.${node.tag}`);
|
||||
}
|
||||
yield* generateStyleScopedClassReferences(options, node);
|
||||
for (const child of node.children) {
|
||||
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, child);
|
||||
}
|
||||
}
|
||||
function* generateStyleScopedClassReferences({ template, typescript: ts }, node) {
|
||||
for (const prop of node.props) {
|
||||
if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE
|
||||
&& prop.name === 'class'
|
||||
&& prop.value) {
|
||||
const [text, start] = (0, shared_2.normalizeAttributeValue)(prop.value);
|
||||
for (const [className, offset] of forEachClassName(text)) {
|
||||
yield* (0, styleScopedClasses_1.generateStyleScopedClassReference)(template, className, start + offset);
|
||||
}
|
||||
}
|
||||
else if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
||||
&& prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
||||
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
||||
&& prop.arg.content === 'class') {
|
||||
const content = '(' + prop.exp.content + ')';
|
||||
const startOffset = prop.exp.loc.start.offset - 1;
|
||||
const ast = (0, utils_1.getTypeScriptAST)(ts, template, content);
|
||||
const literals = [];
|
||||
for (const node of (0, utils_1.forEachNode)(ts, ast)) {
|
||||
if (!ts.isExpressionStatement(node)
|
||||
|| !ts.isParenthesizedExpression(node.expression)) {
|
||||
continue;
|
||||
}
|
||||
const { expression } = node.expression;
|
||||
if (ts.isStringLiteralLike(expression)) {
|
||||
literals.push(expression);
|
||||
}
|
||||
else if (ts.isArrayLiteralExpression(expression)) {
|
||||
yield* walkArrayLiteral(expression);
|
||||
}
|
||||
else if (ts.isObjectLiteralExpression(expression)) {
|
||||
yield* walkObjectLiteral(expression);
|
||||
}
|
||||
}
|
||||
for (const literal of literals) {
|
||||
const start = literal.end - literal.text.length - 1 + startOffset;
|
||||
for (const [className, offset] of forEachClassName(literal.text)) {
|
||||
yield* (0, styleScopedClasses_1.generateStyleScopedClassReference)(template, className, start + offset);
|
||||
}
|
||||
}
|
||||
function* walkArrayLiteral(node) {
|
||||
const { elements } = node;
|
||||
for (const element of elements) {
|
||||
if (ts.isStringLiteralLike(element)) {
|
||||
literals.push(element);
|
||||
}
|
||||
else if (ts.isObjectLiteralExpression(element)) {
|
||||
yield* walkObjectLiteral(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
function* walkObjectLiteral(node) {
|
||||
const { properties } = node;
|
||||
for (const property of properties) {
|
||||
if (ts.isPropertyAssignment(property)) {
|
||||
const { name } = property;
|
||||
if (ts.isIdentifier(name)) {
|
||||
const text = (0, shared_2.getNodeText)(ts, name, ast);
|
||||
yield* (0, styleScopedClasses_1.generateStyleScopedClassReference)(template, text, name.end - text.length + startOffset);
|
||||
}
|
||||
else if (ts.isStringLiteral(name)) {
|
||||
literals.push(name);
|
||||
}
|
||||
else if (ts.isComputedPropertyName(name)) {
|
||||
const { expression } = name;
|
||||
if (ts.isStringLiteralLike(expression)) {
|
||||
literals.push(expression);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (ts.isShorthandPropertyAssignment(property)) {
|
||||
const text = (0, shared_2.getNodeText)(ts, property.name, ast);
|
||||
yield* (0, styleScopedClasses_1.generateStyleScopedClassReference)(template, text, property.name.end - text.length + startOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function* forEachClassName(content) {
|
||||
let offset = 0;
|
||||
for (const className of content.split(' ')) {
|
||||
yield [className, offset];
|
||||
offset += className.length + 1;
|
||||
}
|
||||
}
|
||||
function* generateFailedExpressions(options, ctx, failGeneratedExpressions) {
|
||||
for (const failedExp of failGeneratedExpressions) {
|
||||
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, failedExp.node.loc.source, failedExp.node.loc.start.offset, failedExp.prefix, failedExp.suffix);
|
||||
yield utils_1.endOfLine;
|
||||
}
|
||||
}
|
||||
function getTemplateRef(node) {
|
||||
for (const prop of node.props) {
|
||||
if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE
|
||||
&& prop.name === 'ref'
|
||||
&& prop.value) {
|
||||
return (0, shared_2.normalizeAttributeValue)(prop.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
function hasVBindAttrs(options, ctx, node) {
|
||||
return options.vueCompilerOptions.fallthroughAttributes && ((options.inheritAttrs && ctx.singleRootNodes.has(node))
|
||||
|| node.props.some(prop => prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
||||
&& prop.name === 'bind'
|
||||
&& prop.exp?.loc.source === '$attrs'));
|
||||
}
|
||||
//# sourceMappingURL=element.js.map
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
import * as CompilerDOM from '@vue/compiler-dom';
|
||||
import type { Code } from '../../types';
|
||||
import type { TemplateCodegenContext } from './context';
|
||||
import type { TemplateCodegenOptions } from './index';
|
||||
export declare function generateElementDirectives(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode): Generator<Code>;
|
||||
export declare function generateModifiers(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode, propertyName?: string): Generator<Code>;
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateElementDirectives = generateElementDirectives;
|
||||
exports.generateModifiers = generateModifiers;
|
||||
const CompilerDOM = __importStar(require("@vue/compiler-dom"));
|
||||
const shared_1 = require("@vue/shared");
|
||||
const codeFeatures_1 = require("../codeFeatures");
|
||||
const names = __importStar(require("../names"));
|
||||
const utils_1 = require("../utils");
|
||||
const boundary_1 = require("../utils/boundary");
|
||||
const camelized_1 = require("../utils/camelized");
|
||||
const stringLiteralKey_1 = require("../utils/stringLiteralKey");
|
||||
const elementProps_1 = require("./elementProps");
|
||||
const interpolation_1 = require("./interpolation");
|
||||
const objectProperty_1 = require("./objectProperty");
|
||||
function* generateElementDirectives(options, ctx, node) {
|
||||
for (const prop of node.props) {
|
||||
if (prop.type !== CompilerDOM.NodeTypes.DIRECTIVE
|
||||
|| prop.name === 'slot'
|
||||
|| prop.name === 'on'
|
||||
|| prop.name === 'model'
|
||||
|| prop.name === 'bind') {
|
||||
continue;
|
||||
}
|
||||
const token = yield* (0, boundary_1.startBoundary)('template', prop.loc.start.offset, codeFeatures_1.codeFeatures.verification);
|
||||
yield `__VLS_asFunctionalDirective(`;
|
||||
yield* generateIdentifier(options, ctx, prop);
|
||||
yield `, {} as import('${options.vueCompilerOptions.lib}').ObjectDirective)(null!, { ...__VLS_directiveBindingRestFields, `;
|
||||
yield* generateArg(options, ctx, prop);
|
||||
yield* generateModifiers(options, ctx, prop);
|
||||
yield* generateValue(options, ctx, prop);
|
||||
yield ` }, null!, null!)`;
|
||||
yield (0, boundary_1.endBoundary)(token, prop.loc.end.offset);
|
||||
yield utils_1.endOfLine;
|
||||
}
|
||||
}
|
||||
function* generateIdentifier(options, ctx, prop) {
|
||||
const rawName = 'v-' + prop.name;
|
||||
const startOffset = prop.loc.start.offset;
|
||||
const token = yield* (0, boundary_1.startBoundary)('template', startOffset, codeFeatures_1.codeFeatures.verification);
|
||||
yield names.directives;
|
||||
yield `.`;
|
||||
yield* (0, camelized_1.generateCamelized)(rawName, 'template', prop.loc.start.offset, {
|
||||
...codeFeatures_1.codeFeatures.withoutHighlightAndCompletion,
|
||||
verification: options.vueCompilerOptions.checkUnknownDirectives && !(0, shared_1.isBuiltInDirective)(prop.name),
|
||||
});
|
||||
if (!(0, shared_1.isBuiltInDirective)(prop.name)) {
|
||||
ctx.recordComponentAccess('template', (0, shared_1.camelize)(rawName), prop.loc.start.offset);
|
||||
}
|
||||
yield (0, boundary_1.endBoundary)(token, startOffset + rawName.length);
|
||||
}
|
||||
function* generateArg(options, ctx, prop) {
|
||||
const { arg } = prop;
|
||||
if (arg?.type !== CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
||||
return;
|
||||
}
|
||||
const startOffset = arg.loc.start.offset + arg.loc.source.indexOf(arg.content);
|
||||
const token = yield* (0, boundary_1.startBoundary)('template', startOffset, codeFeatures_1.codeFeatures.verification);
|
||||
yield `arg`;
|
||||
yield (0, boundary_1.endBoundary)(token, startOffset + arg.content.length);
|
||||
yield `: `;
|
||||
if (arg.isStatic) {
|
||||
yield* (0, stringLiteralKey_1.generateStringLiteralKey)(arg.content, startOffset, codeFeatures_1.codeFeatures.all);
|
||||
}
|
||||
else {
|
||||
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, arg.content, startOffset, `(`, `)`);
|
||||
}
|
||||
yield `, `;
|
||||
}
|
||||
function* generateModifiers(options, ctx, prop, propertyName = 'modifiers') {
|
||||
const { modifiers } = prop;
|
||||
if (!modifiers.length) {
|
||||
return;
|
||||
}
|
||||
const startOffset = modifiers[0].loc.start.offset - 1;
|
||||
const endOffset = modifiers.at(-1).loc.end.offset;
|
||||
const token = yield* (0, boundary_1.startBoundary)('template', startOffset, codeFeatures_1.codeFeatures.verification);
|
||||
yield propertyName;
|
||||
yield (0, boundary_1.endBoundary)(token, endOffset);
|
||||
yield `: { `;
|
||||
for (const mod of modifiers) {
|
||||
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, mod.content, mod.loc.start.offset, codeFeatures_1.codeFeatures.withoutHighlight);
|
||||
yield `: true, `;
|
||||
}
|
||||
yield `}, `;
|
||||
}
|
||||
function* generateValue(options, ctx, prop) {
|
||||
const { exp } = prop;
|
||||
if (exp?.type !== CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
||||
return;
|
||||
}
|
||||
const token = yield* (0, boundary_1.startBoundary)('template', exp.loc.start.offset, codeFeatures_1.codeFeatures.verification);
|
||||
yield `value`;
|
||||
yield (0, boundary_1.endBoundary)(token, exp.loc.end.offset);
|
||||
yield `: `;
|
||||
yield* (0, elementProps_1.generatePropExp)(options, ctx, prop, exp);
|
||||
}
|
||||
//# sourceMappingURL=elementDirectives.js.map
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import * as CompilerDOM from '@vue/compiler-dom';
|
||||
import type * as ts from 'typescript';
|
||||
import type { Code, VueCodeInformation } from '../../types';
|
||||
import type { TemplateCodegenContext } from './context';
|
||||
import type { TemplateCodegenOptions } from './index';
|
||||
export declare function generateElementEvents(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, componentOriginalVar: string, getCtxVar: () => string, getPropsVar: () => string): Generator<Code>;
|
||||
export declare function generateEventArg(options: TemplateCodegenOptions, name: string, start: number, directive?: string, features?: VueCodeInformation): Generator<Code>;
|
||||
export declare function generateEventExpression(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode): Generator<Code>;
|
||||
export declare function generateModelEventExpression(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode): Generator<Code>;
|
||||
export declare function isCompoundExpression(ts: typeof import('typescript'), ast: ts.SourceFile): boolean;
|
||||
+203
@@ -0,0 +1,203 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateElementEvents = generateElementEvents;
|
||||
exports.generateEventArg = generateEventArg;
|
||||
exports.generateEventExpression = generateEventExpression;
|
||||
exports.generateModelEventExpression = generateModelEventExpression;
|
||||
exports.isCompoundExpression = isCompoundExpression;
|
||||
const CompilerDOM = __importStar(require("@vue/compiler-dom"));
|
||||
const shared_1 = require("@vue/shared");
|
||||
const codeFeatures_1 = require("../codeFeatures");
|
||||
const utils_1 = require("../utils");
|
||||
const boundary_1 = require("../utils/boundary");
|
||||
const camelized_1 = require("../utils/camelized");
|
||||
const interpolation_1 = require("./interpolation");
|
||||
function* generateElementEvents(options, ctx, node, componentOriginalVar, getCtxVar, getPropsVar) {
|
||||
let emitsVar;
|
||||
for (const prop of node.props) {
|
||||
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
||||
&& (prop.name === 'on'
|
||||
&& (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic)
|
||||
|| options.vueCompilerOptions.strictVModel
|
||||
&& prop.name === 'model'
|
||||
&& (!prop.arg || prop.arg.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic))) {
|
||||
if (!emitsVar) {
|
||||
emitsVar = ctx.getInternalVariable();
|
||||
yield `let ${emitsVar}!: __VLS_ResolveEmits<typeof ${componentOriginalVar}, typeof ${getCtxVar()}.emit>${utils_1.endOfLine}`;
|
||||
}
|
||||
let source = prop.arg?.loc.source ?? 'model-value';
|
||||
let start = prop.arg?.loc.start.offset;
|
||||
let propPrefix = 'on-';
|
||||
let emitPrefix = '';
|
||||
if (prop.name === 'model') {
|
||||
propPrefix = 'onUpdate:';
|
||||
emitPrefix = 'update:';
|
||||
}
|
||||
else if (source.startsWith('vue:')) {
|
||||
source = source.slice('vue:'.length);
|
||||
start = start + 'vue:'.length;
|
||||
propPrefix = 'onVnode-';
|
||||
emitPrefix = 'vnode-';
|
||||
}
|
||||
const propName = (0, shared_1.camelize)(propPrefix + source);
|
||||
const emitName = emitPrefix + source;
|
||||
const camelizedEmitName = (0, shared_1.camelize)(emitName);
|
||||
yield `const ${ctx.getInternalVariable()}: __VLS_NormalizeComponentEvent<typeof ${getPropsVar()}, typeof ${emitsVar}, '${propName}', '${emitName}', '${camelizedEmitName}'> = (${utils_1.newLine}`;
|
||||
if (prop.name === 'on') {
|
||||
yield `{ `;
|
||||
yield* generateEventArg(options, source, start, emitPrefix.slice(0, -1), codeFeatures_1.codeFeatures.navigation);
|
||||
yield `: {} as any } as typeof ${emitsVar},${utils_1.newLine}`;
|
||||
}
|
||||
yield `{ `;
|
||||
if (prop.name === 'on') {
|
||||
yield* generateEventArg(options, source, start, propPrefix.slice(0, -1));
|
||||
yield `: `;
|
||||
yield* generateEventExpression(options, ctx, prop);
|
||||
}
|
||||
else {
|
||||
yield `'${propName}': `;
|
||||
yield* generateModelEventExpression(options, ctx, prop);
|
||||
}
|
||||
yield `})${utils_1.endOfLine}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
function* generateEventArg(options, name, start, directive = 'on', features) {
|
||||
features ??= {
|
||||
...codeFeatures_1.codeFeatures.semanticWithoutHighlight,
|
||||
...codeFeatures_1.codeFeatures.navigationWithoutRename,
|
||||
...options.vueCompilerOptions.checkUnknownEvents
|
||||
? codeFeatures_1.codeFeatures.verification
|
||||
: codeFeatures_1.codeFeatures.doNotReportTs2353AndTs2561,
|
||||
};
|
||||
if (directive.length) {
|
||||
name = (0, shared_1.capitalize)(name);
|
||||
}
|
||||
if (utils_1.identifierRegex.test((0, shared_1.camelize)(name))) {
|
||||
const token = yield* (0, boundary_1.startBoundary)('template', start, features);
|
||||
yield directive;
|
||||
yield* (0, camelized_1.generateCamelized)(name, 'template', start, { __combineToken: token });
|
||||
}
|
||||
else {
|
||||
const token = yield* (0, boundary_1.startBoundary)('template', start, features);
|
||||
yield `'`;
|
||||
yield directive;
|
||||
yield* (0, camelized_1.generateCamelized)(name, 'template', start, { __combineToken: token });
|
||||
yield `'`;
|
||||
yield (0, boundary_1.endBoundary)(token, start + name.length);
|
||||
}
|
||||
}
|
||||
function* generateEventExpression(options, ctx, prop) {
|
||||
if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
||||
const ast = (0, utils_1.getTypeScriptAST)(options.typescript, options.template, prop.exp.content);
|
||||
const isCompound = isCompoundExpression(options.typescript, ast);
|
||||
const interpolation = (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, prop.exp.content, prop.exp.loc.start.offset, isCompound ? `` : `(`, isCompound ? `` : `)`);
|
||||
if (isCompound) {
|
||||
yield `(...[$event]) => {${utils_1.newLine}`;
|
||||
const endScope = ctx.startScope();
|
||||
ctx.declare('$event');
|
||||
yield* ctx.generateConditionGuards();
|
||||
yield* interpolation;
|
||||
yield utils_1.endOfLine;
|
||||
yield* endScope();
|
||||
yield `}`;
|
||||
ctx.inlayHints.push({
|
||||
blockName: 'template',
|
||||
offset: prop.exp.loc.start.offset,
|
||||
setting: 'vue.inlayHints.inlineHandlerLeading',
|
||||
label: '$event =>',
|
||||
paddingRight: true,
|
||||
tooltip: [
|
||||
'`$event` is a hidden parameter, you can use it in this callback.',
|
||||
'To hide this hint, set `vue.inlayHints.inlineHandlerLeading` to `false` in IDE settings.',
|
||||
'[More info](https://github.com/vuejs/language-tools/issues/2445#issuecomment-1444771420)',
|
||||
].join('\n\n'),
|
||||
});
|
||||
}
|
||||
else {
|
||||
yield* interpolation;
|
||||
}
|
||||
}
|
||||
else {
|
||||
yield `() => {}`;
|
||||
}
|
||||
}
|
||||
function* generateModelEventExpression(options, ctx, prop) {
|
||||
if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
||||
yield `(...[$event]) => {${utils_1.newLine}`;
|
||||
yield* ctx.generateConditionGuards();
|
||||
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.verification, prop.exp.content, prop.exp.loc.start.offset);
|
||||
yield ` = $event${utils_1.endOfLine}`;
|
||||
yield `}`;
|
||||
}
|
||||
else {
|
||||
yield `() => {}`;
|
||||
}
|
||||
}
|
||||
function isCompoundExpression(ts, ast) {
|
||||
let result = true;
|
||||
if (ast.statements.length === 0) {
|
||||
result = false;
|
||||
}
|
||||
else if (ast.statements.length === 1) {
|
||||
ts.forEachChild(ast, child_1 => {
|
||||
if (ts.isExpressionStatement(child_1)) {
|
||||
ts.forEachChild(child_1, child_2 => {
|
||||
if (ts.isArrowFunction(child_2)) {
|
||||
result = false;
|
||||
}
|
||||
else if (isPropertyAccessOrId(ts, child_2)) {
|
||||
result = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (ts.isFunctionDeclaration(child_1)) {
|
||||
result = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function isPropertyAccessOrId(ts, node) {
|
||||
if (ts.isIdentifier(node)) {
|
||||
return true;
|
||||
}
|
||||
if (ts.isPropertyAccessExpression(node)) {
|
||||
return isPropertyAccessOrId(ts, node.expression);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
//# sourceMappingURL=elementEvents.js.map
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import * as CompilerDOM from '@vue/compiler-dom';
|
||||
import type { Code } from '../../types';
|
||||
import type { TemplateCodegenContext } from './context';
|
||||
import type { TemplateCodegenOptions } from './index';
|
||||
export interface FailGeneratedExpression {
|
||||
node: CompilerDOM.SimpleExpressionNode;
|
||||
prefix: string;
|
||||
suffix: string;
|
||||
}
|
||||
export declare function generateElementProps(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, props: CompilerDOM.ElementNode['props'], strictPropsCheck: boolean, failGeneratedExpressions?: FailGeneratedExpression[]): Generator<Code>;
|
||||
export declare function generatePropExp(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode, exp: CompilerDOM.SimpleExpressionNode | undefined): Generator<Code>;
|
||||
+291
@@ -0,0 +1,291 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateElementProps = generateElementProps;
|
||||
exports.generatePropExp = generatePropExp;
|
||||
const CompilerDOM = __importStar(require("@vue/compiler-dom"));
|
||||
const shared_1 = require("@vue/shared");
|
||||
const picomatch_1 = require("picomatch");
|
||||
const shared_2 = require("../../utils/shared");
|
||||
const codeFeatures_1 = require("../codeFeatures");
|
||||
const inlayHints_1 = require("../inlayHints");
|
||||
const names = __importStar(require("../names"));
|
||||
const utils_1 = require("../utils");
|
||||
const boundary_1 = require("../utils/boundary");
|
||||
const camelized_1 = require("../utils/camelized");
|
||||
const unicode_1 = require("../utils/unicode");
|
||||
const elementDirectives_1 = require("./elementDirectives");
|
||||
const elementEvents_1 = require("./elementEvents");
|
||||
const interpolation_1 = require("./interpolation");
|
||||
const objectProperty_1 = require("./objectProperty");
|
||||
function* generateElementProps(options, ctx, node, props, strictPropsCheck, failGeneratedExpressions) {
|
||||
const isComponent = node.tagType === CompilerDOM.ElementTypes.COMPONENT;
|
||||
for (const prop of props) {
|
||||
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
||||
&& prop.name === 'on') {
|
||||
if (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
||||
&& !prop.arg.loc.source.startsWith('[')
|
||||
&& !prop.arg.loc.source.endsWith(']')) {
|
||||
if (!isComponent) {
|
||||
yield `...{ `;
|
||||
yield* (0, elementEvents_1.generateEventArg)(options, prop.arg.loc.source, prop.arg.loc.start.offset);
|
||||
yield `: `;
|
||||
yield* (0, elementEvents_1.generateEventExpression)(options, ctx, prop);
|
||||
yield `},`;
|
||||
}
|
||||
else {
|
||||
yield `...{ '${(0, shared_1.camelize)('on-' + prop.arg.loc.source)}': {} as any },`;
|
||||
}
|
||||
yield utils_1.newLine;
|
||||
}
|
||||
else if (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
||||
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
||||
&& prop.arg.loc.source.startsWith('[')
|
||||
&& prop.arg.loc.source.endsWith(']')) {
|
||||
failGeneratedExpressions?.push({ node: prop.arg, prefix: `(`, suffix: `)` });
|
||||
failGeneratedExpressions?.push({ node: prop.exp, prefix: `() => {`, suffix: `}` });
|
||||
}
|
||||
else if (!prop.arg
|
||||
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
||||
failGeneratedExpressions?.push({ node: prop.exp, prefix: `(`, suffix: `)` });
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const prop of props) {
|
||||
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
||||
&& ((prop.name === 'bind' && prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION)
|
||||
|| prop.name === 'model')
|
||||
&& (!prop.exp || prop.exp.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION)) {
|
||||
let propName;
|
||||
if (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
||||
propName = prop.arg.constType === CompilerDOM.ConstantTypes.CAN_STRINGIFY
|
||||
? prop.arg.content
|
||||
: prop.arg.loc.source;
|
||||
}
|
||||
else {
|
||||
propName = getModelPropName(node, options.vueCompilerOptions);
|
||||
}
|
||||
if (propName === undefined
|
||||
|| options.vueCompilerOptions.dataAttributes.some(pattern => (0, picomatch_1.isMatch)(propName, pattern))) {
|
||||
if (prop.exp && prop.exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY) {
|
||||
failGeneratedExpressions?.push({ node: prop.exp, prefix: `(`, suffix: `)` });
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (prop.name === 'bind'
|
||||
&& prop.modifiers.some(m => m.content === 'prop' || m.content === 'attr')) {
|
||||
propName = propName.slice(1);
|
||||
}
|
||||
const shouldSpread = propName === 'style' || propName === 'class';
|
||||
const shouldCamelize = isComponent && getShouldCamelize(options, prop, propName);
|
||||
const features = getPropsCodeFeatures(strictPropsCheck);
|
||||
if (shouldSpread) {
|
||||
yield `...{ `;
|
||||
}
|
||||
const token = yield* (0, boundary_1.startBoundary)('template', prop.loc.start.offset, codeFeatures_1.codeFeatures.verification);
|
||||
if (prop.arg) {
|
||||
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, propName, prop.arg.loc.start.offset, features, shouldCamelize);
|
||||
}
|
||||
else {
|
||||
const token2 = yield* (0, boundary_1.startBoundary)('template', prop.loc.start.offset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
|
||||
yield propName;
|
||||
yield (0, boundary_1.endBoundary)(token2, prop.loc.start.offset + 'v-model'.length);
|
||||
}
|
||||
yield `: `;
|
||||
const argLoc = prop.arg?.loc ?? prop.loc;
|
||||
const token3 = yield* (0, boundary_1.startBoundary)('template', argLoc.start.offset, codeFeatures_1.codeFeatures.verification);
|
||||
yield* generatePropExp(options, ctx, prop, prop.exp);
|
||||
yield (0, boundary_1.endBoundary)(token3, argLoc.end.offset);
|
||||
yield (0, boundary_1.endBoundary)(token, prop.loc.end.offset);
|
||||
if (shouldSpread) {
|
||||
yield ` }`;
|
||||
}
|
||||
yield `,${utils_1.newLine}`;
|
||||
if (isComponent && prop.name === 'model' && prop.modifiers.length) {
|
||||
const propertyName = prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
||||
? !prop.arg.isStatic
|
||||
? `[__VLS_tryAsConstant(\`\${${prop.arg.content}}Modifiers\`)]`
|
||||
: (0, shared_1.camelize)(propName) + `Modifiers`
|
||||
: `modelModifiers`;
|
||||
yield* (0, elementDirectives_1.generateModifiers)(options, ctx, prop, propertyName);
|
||||
yield utils_1.newLine;
|
||||
}
|
||||
}
|
||||
else if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE) {
|
||||
if (options.vueCompilerOptions.dataAttributes.some(pattern => (0, picomatch_1.isMatch)(prop.name, pattern))) {
|
||||
continue;
|
||||
}
|
||||
const shouldSpread = prop.name === 'style' || prop.name === 'class';
|
||||
const shouldCamelize = isComponent && getShouldCamelize(options, prop, prop.name);
|
||||
const features = getPropsCodeFeatures(strictPropsCheck);
|
||||
if (shouldSpread) {
|
||||
yield `...{ `;
|
||||
}
|
||||
const token = yield* (0, boundary_1.startBoundary)('template', prop.loc.start.offset, codeFeatures_1.codeFeatures.verification);
|
||||
const prefix = options.template.content.slice(prop.loc.start.offset, prop.loc.start.offset + 1);
|
||||
if (prefix === '.' || prefix === '#') {
|
||||
// Pug shorthand syntax
|
||||
for (const char of prop.name) {
|
||||
yield [char, 'template', prop.loc.start.offset, features];
|
||||
}
|
||||
}
|
||||
else {
|
||||
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, prop.name, prop.loc.start.offset, features, shouldCamelize);
|
||||
}
|
||||
yield `: `;
|
||||
if (prop.name === 'style') {
|
||||
yield `{}`;
|
||||
}
|
||||
else if (prop.value) {
|
||||
yield* generateAttrValue(prop.value, codeFeatures_1.codeFeatures.withoutNavigation);
|
||||
}
|
||||
else {
|
||||
yield `true`;
|
||||
}
|
||||
yield (0, boundary_1.endBoundary)(token, prop.loc.end.offset);
|
||||
if (shouldSpread) {
|
||||
yield ` }`;
|
||||
}
|
||||
yield `,${utils_1.newLine}`;
|
||||
}
|
||||
else if (prop.name === 'bind'
|
||||
&& !prop.arg
|
||||
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
||||
if (prop.exp.loc.source === '$attrs') {
|
||||
failGeneratedExpressions?.push({ node: prop.exp, prefix: `(`, suffix: `)` });
|
||||
}
|
||||
else {
|
||||
const token = yield* (0, boundary_1.startBoundary)('template', prop.exp.loc.start.offset, codeFeatures_1.codeFeatures.verification);
|
||||
yield `...`;
|
||||
yield* generatePropExp(options, ctx, prop, prop.exp);
|
||||
yield (0, boundary_1.endBoundary)(token, prop.exp.loc.end.offset);
|
||||
yield `,${utils_1.newLine}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function* generatePropExp(options, ctx, prop, exp) {
|
||||
if (!exp) {
|
||||
yield `{}`;
|
||||
}
|
||||
else if (prop.arg?.loc.start.offset !== prop.exp?.loc.start.offset) {
|
||||
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, exp.loc.source, exp.loc.start.offset, `(`, `)`);
|
||||
}
|
||||
else {
|
||||
const propVariableName = (0, shared_1.camelize)(exp.loc.source);
|
||||
if (utils_1.identifierRegex.test(propVariableName)) {
|
||||
const codes = (0, camelized_1.generateCamelized)(exp.loc.source, 'template', exp.loc.start.offset, {
|
||||
...codeFeatures_1.codeFeatures.withoutHighlightAndCompletion,
|
||||
__shorthandExpression: 'html',
|
||||
});
|
||||
if (ctx.scopes.some(scope => scope.has(propVariableName))) {
|
||||
yield* codes;
|
||||
}
|
||||
else if (options.setupRefs.has(propVariableName)) {
|
||||
yield* codes;
|
||||
yield `.value`;
|
||||
}
|
||||
else {
|
||||
ctx.recordComponentAccess('template', propVariableName, exp.loc.start.offset);
|
||||
yield names.ctx;
|
||||
yield `.`;
|
||||
yield* codes;
|
||||
}
|
||||
ctx.inlayHints.push((0, inlayHints_1.createVBindShorthandInlayHintInfo)(prop.loc, propVariableName));
|
||||
}
|
||||
}
|
||||
}
|
||||
function* generateAttrValue(node, features) {
|
||||
const quote = node.loc.source.startsWith("'") ? "'" : '"';
|
||||
const [content, offset] = (0, shared_2.normalizeAttributeValue)(node);
|
||||
yield quote;
|
||||
yield* (0, unicode_1.generateUnicode)(content, offset, features);
|
||||
yield quote;
|
||||
}
|
||||
function getShouldCamelize(options, prop, propName) {
|
||||
return (prop.type !== CompilerDOM.NodeTypes.DIRECTIVE
|
||||
|| !prop.arg
|
||||
|| (prop.arg.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic))
|
||||
&& (0, shared_2.hyphenateAttr)(propName) === propName
|
||||
&& !options.vueCompilerOptions.htmlAttributes.some(pattern => (0, picomatch_1.isMatch)(propName, pattern));
|
||||
}
|
||||
function getPropsCodeFeatures(strictPropsCheck) {
|
||||
return {
|
||||
...codeFeatures_1.codeFeatures.withoutHighlightAndCompletion,
|
||||
...strictPropsCheck
|
||||
? codeFeatures_1.codeFeatures.verification
|
||||
: codeFeatures_1.codeFeatures.doNotReportTs2353AndTs2561,
|
||||
};
|
||||
}
|
||||
function getModelPropName(node, vueCompilerOptions) {
|
||||
for (const modelName in vueCompilerOptions.experimentalModelPropName) {
|
||||
const tags = vueCompilerOptions.experimentalModelPropName[modelName];
|
||||
for (const tag in tags) {
|
||||
if (node.tag === tag || node.tag === (0, shared_2.hyphenateTag)(tag)) {
|
||||
const val = tags[tag];
|
||||
if (typeof val === 'object') {
|
||||
const arr = Array.isArray(val) ? val : [val];
|
||||
for (const attrs of arr) {
|
||||
let failed = false;
|
||||
for (const attr in attrs) {
|
||||
const attrNode = node.props.find(prop => prop.type === CompilerDOM.NodeTypes.ATTRIBUTE && prop.name === attr);
|
||||
if (!attrNode || attrNode.value?.content !== attrs[attr]) {
|
||||
failed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!failed) {
|
||||
// all match
|
||||
return modelName || undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const modelName in vueCompilerOptions.experimentalModelPropName) {
|
||||
const tags = vueCompilerOptions.experimentalModelPropName[modelName];
|
||||
for (const tag in tags) {
|
||||
if (node.tag === tag || node.tag === (0, shared_2.hyphenateTag)(tag)) {
|
||||
const attrs = tags[tag];
|
||||
if (attrs === true) {
|
||||
return modelName || undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 'modelValue';
|
||||
}
|
||||
//# sourceMappingURL=elementProps.js.map
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
import type * as ts from 'typescript';
|
||||
import type { Code, Sfc, VueCompilerOptions } from '../../types';
|
||||
export interface TemplateCodegenOptions {
|
||||
typescript: typeof ts;
|
||||
vueCompilerOptions: VueCompilerOptions;
|
||||
template: NonNullable<Sfc['template']>;
|
||||
setupRefs: Set<string>;
|
||||
setupConsts: Set<string>;
|
||||
hasDefineSlots?: boolean;
|
||||
propsAssignName?: string;
|
||||
slotsAssignName?: string;
|
||||
inheritAttrs: boolean;
|
||||
componentName: string;
|
||||
}
|
||||
export { generate as generateTemplate };
|
||||
declare function generate(options: TemplateCodegenOptions): {
|
||||
generatedTypes: Set<string>;
|
||||
currentInfo: {
|
||||
ignoreError?: boolean | undefined;
|
||||
expectError?: {
|
||||
token: number;
|
||||
node: import("@vue/compiler-dom").CommentNode;
|
||||
} | undefined;
|
||||
generic?: {
|
||||
content: string;
|
||||
offset: number;
|
||||
} | undefined;
|
||||
};
|
||||
resolveCodeFeatures: (features: import("../../types").VueCodeInformation) => import("../../types").VueCodeInformation;
|
||||
inVFor: boolean;
|
||||
slots: {
|
||||
name: string;
|
||||
offset?: number | undefined;
|
||||
tagRange: [number, number];
|
||||
nodeLoc: any;
|
||||
propsVar: string;
|
||||
}[];
|
||||
dynamicSlots: {
|
||||
expVar: string;
|
||||
propsVar: string;
|
||||
}[];
|
||||
dollarVars: Set<string>;
|
||||
componentAccessMap: Map<string, Map<string, Set<number>>>;
|
||||
blockConditions: string[];
|
||||
inlayHints: import("../inlayHints").InlayHintInfo[];
|
||||
inheritedAttrVars: Set<string>;
|
||||
templateRefs: Map<string, {
|
||||
typeExp: string;
|
||||
offset: number;
|
||||
}[]>;
|
||||
singleRootElTypes: Set<string>;
|
||||
singleRootNodes: Set<import("@vue/compiler-dom").ElementNode | null>;
|
||||
addTemplateRef(name: string, typeExp: string, offset: number): void;
|
||||
recordComponentAccess(source: string, name: string, offset?: number | undefined): void;
|
||||
scopes: Set<string>[];
|
||||
components: (() => string)[];
|
||||
declare(...varNames: string[]): void;
|
||||
startScope(): () => Generator<Code, any, any>;
|
||||
getInternalVariable(): string;
|
||||
getHoistVariable(originalVar: string): string;
|
||||
generateHoistVariables(): Generator<string, void, unknown>;
|
||||
generateConditionGuards(): Generator<string, void, unknown>;
|
||||
enter(node: import("@vue/compiler-dom").RootNode | import("@vue/compiler-dom").SimpleExpressionNode | import("@vue/compiler-dom").TemplateChildNode): boolean;
|
||||
exit(): Generator<Code, any, any>;
|
||||
codes: Code[];
|
||||
};
|
||||
+183
@@ -0,0 +1,183 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateTemplate = generate;
|
||||
const codeFeatures_1 = require("../codeFeatures");
|
||||
const names = __importStar(require("../names"));
|
||||
const utils_1 = require("../utils");
|
||||
const boundary_1 = require("../utils/boundary");
|
||||
const context_1 = require("./context");
|
||||
const objectProperty_1 = require("./objectProperty");
|
||||
const templateChild_1 = require("./templateChild");
|
||||
function generate(options) {
|
||||
const ctx = (0, context_1.createTemplateCodegenContext)();
|
||||
const codeGenerator = generateWorker(options, ctx);
|
||||
const codes = [];
|
||||
for (const code of codeGenerator) {
|
||||
if (typeof code === 'object') {
|
||||
code[3] = ctx.resolveCodeFeatures(code[3]);
|
||||
}
|
||||
codes.push(code);
|
||||
}
|
||||
return { ...ctx, codes };
|
||||
}
|
||||
function* generateWorker(options, ctx) {
|
||||
const endScope = ctx.startScope();
|
||||
ctx.declare(...options.setupConsts);
|
||||
const { slotsAssignName, propsAssignName, vueCompilerOptions, template, } = options;
|
||||
if (slotsAssignName) {
|
||||
ctx.declare(slotsAssignName);
|
||||
}
|
||||
if (propsAssignName) {
|
||||
ctx.declare(propsAssignName);
|
||||
}
|
||||
if (vueCompilerOptions.inferTemplateDollarSlots) {
|
||||
ctx.dollarVars.add('$slots');
|
||||
}
|
||||
if (vueCompilerOptions.inferTemplateDollarAttrs) {
|
||||
ctx.dollarVars.add('$attrs');
|
||||
}
|
||||
if (vueCompilerOptions.inferTemplateDollarRefs) {
|
||||
ctx.dollarVars.add('$refs');
|
||||
}
|
||||
if (vueCompilerOptions.inferTemplateDollarEl) {
|
||||
ctx.dollarVars.add('$el');
|
||||
}
|
||||
if (template.ast) {
|
||||
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, template.ast);
|
||||
}
|
||||
yield* ctx.generateHoistVariables();
|
||||
yield* generateSlotsType(options, ctx);
|
||||
yield* generateInheritedAttrsType(ctx);
|
||||
yield* generateTemplateRefsType(options, ctx);
|
||||
yield* generateRootElType(ctx);
|
||||
if (ctx.dollarVars.size) {
|
||||
yield `var ${names.dollars}!: {${utils_1.newLine}`;
|
||||
if (ctx.dollarVars.has('$slots')) {
|
||||
const type = ctx.generatedTypes.has(names.Slots) ? names.Slots : `{}`;
|
||||
yield `$slots: ${type}${utils_1.endOfLine}`;
|
||||
}
|
||||
if (ctx.dollarVars.has('$attrs')) {
|
||||
yield `$attrs: import('${vueCompilerOptions.lib}').ComponentPublicInstance['$attrs']`;
|
||||
if (ctx.generatedTypes.has(names.InheritedAttrs)) {
|
||||
yield ` & ${names.InheritedAttrs}`;
|
||||
}
|
||||
yield utils_1.endOfLine;
|
||||
}
|
||||
if (ctx.dollarVars.has('$refs')) {
|
||||
const type = ctx.generatedTypes.has(names.TemplateRefs) ? names.TemplateRefs : `{}`;
|
||||
yield `$refs: ${type}${utils_1.endOfLine}`;
|
||||
}
|
||||
if (ctx.dollarVars.has('$el')) {
|
||||
const type = ctx.generatedTypes.has(names.RootEl) ? names.RootEl : `any`;
|
||||
yield `$el: ${type}${utils_1.endOfLine}`;
|
||||
}
|
||||
yield `} & { [K in keyof import('${vueCompilerOptions.lib}').ComponentPublicInstance]: unknown }${utils_1.endOfLine}`;
|
||||
}
|
||||
yield* endScope();
|
||||
}
|
||||
function* generateSlotsType(options, ctx) {
|
||||
if (options.hasDefineSlots) {
|
||||
ctx.generatedTypes.add(names.Slots);
|
||||
return;
|
||||
}
|
||||
if (!ctx.slots.length && !ctx.dynamicSlots.length) {
|
||||
return;
|
||||
}
|
||||
ctx.generatedTypes.add(names.Slots);
|
||||
yield `type ${names.Slots} = {}`;
|
||||
for (const { expVar, propsVar } of ctx.dynamicSlots) {
|
||||
yield `${utils_1.newLine}& { [K in NonNullable<typeof ${expVar}>]?: (props: typeof ${propsVar}) => any }`;
|
||||
}
|
||||
for (const slot of ctx.slots) {
|
||||
yield `${utils_1.newLine}& { `;
|
||||
if (slot.name && slot.offset !== undefined) {
|
||||
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slot.name, slot.offset, codeFeatures_1.codeFeatures.navigation);
|
||||
}
|
||||
else {
|
||||
const token = yield* (0, boundary_1.startBoundary)('template', slot.tagRange[0], codeFeatures_1.codeFeatures.navigation);
|
||||
yield `default`;
|
||||
yield (0, boundary_1.endBoundary)(token, slot.tagRange[1]);
|
||||
}
|
||||
yield `?: (props: typeof ${slot.propsVar}) => any }`;
|
||||
}
|
||||
yield utils_1.endOfLine;
|
||||
}
|
||||
function* generateInheritedAttrsType(ctx) {
|
||||
if (!ctx.inheritedAttrVars.size) {
|
||||
return;
|
||||
}
|
||||
ctx.generatedTypes.add(names.InheritedAttrs);
|
||||
yield `type ${names.InheritedAttrs} = Partial<${[...ctx.inheritedAttrVars].map(name => `typeof ${name}`).join(` & `)}>`;
|
||||
yield utils_1.endOfLine;
|
||||
}
|
||||
function* generateTemplateRefsType(options, ctx) {
|
||||
if (!ctx.templateRefs.size) {
|
||||
return;
|
||||
}
|
||||
ctx.generatedTypes.add(names.TemplateRefs);
|
||||
yield `type ${names.TemplateRefs} = {}`;
|
||||
for (const [name, refs] of ctx.templateRefs) {
|
||||
yield `${utils_1.newLine}& `;
|
||||
if (refs.length >= 2) {
|
||||
yield `(`;
|
||||
}
|
||||
for (let i = 0; i < refs.length; i++) {
|
||||
const { typeExp, offset } = refs[i];
|
||||
if (i) {
|
||||
yield ` | `;
|
||||
}
|
||||
yield `{ `;
|
||||
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, name, offset, codeFeatures_1.codeFeatures.navigation);
|
||||
yield `: ${typeExp} }`;
|
||||
}
|
||||
if (refs.length >= 2) {
|
||||
yield `)`;
|
||||
}
|
||||
}
|
||||
yield utils_1.endOfLine;
|
||||
}
|
||||
function* generateRootElType(ctx) {
|
||||
if (!ctx.singleRootElTypes.size || ctx.singleRootNodes.has(null)) {
|
||||
return;
|
||||
}
|
||||
ctx.generatedTypes.add(names.RootEl);
|
||||
yield `type ${names.RootEl} = `;
|
||||
for (const type of ctx.singleRootElTypes) {
|
||||
yield `${utils_1.newLine}| ${type}`;
|
||||
}
|
||||
yield utils_1.endOfLine;
|
||||
}
|
||||
//# sourceMappingURL=index.js.map
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
import type { Code, SfcBlock, VueCodeInformation } from '../../types';
|
||||
import type { TemplateCodegenContext } from './context';
|
||||
export declare function generateInterpolation({ typescript, setupRefs }: {
|
||||
typescript: typeof import('typescript');
|
||||
setupRefs: Set<string>;
|
||||
}, ctx: TemplateCodegenContext, block: SfcBlock, data: VueCodeInformation, code: string, start: number, prefix?: string, suffix?: string): Generator<Code>;
|
||||
+238
@@ -0,0 +1,238 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateInterpolation = generateInterpolation;
|
||||
const shared_1 = require("@vue/shared");
|
||||
const collectBindings_1 = require("../../utils/collectBindings");
|
||||
const shared_2 = require("../../utils/shared");
|
||||
const codeFeatures_1 = require("../codeFeatures");
|
||||
const names = __importStar(require("../names"));
|
||||
const utils_1 = require("../utils");
|
||||
// https://github.com/vuejs/core/blob/fb0c3ca519f1fccf52049cd6b8db3a67a669afe9/packages/compiler-core/src/transforms/transformExpression.ts#L47
|
||||
const isLiteralWhitelisted = /*@__PURE__*/ (0, shared_1.makeMap)('true,false,null,this');
|
||||
function* generateInterpolation({ typescript, setupRefs }, ctx, block, data, code, start, prefix = '', suffix = '') {
|
||||
for (const segment of forEachInterpolationSegment(typescript, setupRefs, ctx, block, code, start, prefix, suffix)) {
|
||||
if (typeof segment === 'string') {
|
||||
yield segment;
|
||||
continue;
|
||||
}
|
||||
let [section, offset, type] = segment;
|
||||
offset -= prefix.length;
|
||||
let addSuffix = '';
|
||||
const overLength = offset + section.length - code.length;
|
||||
if (overLength > 0) {
|
||||
addSuffix = section.slice(section.length - overLength);
|
||||
section = section.slice(0, -overLength);
|
||||
}
|
||||
if (offset < 0) {
|
||||
yield section.slice(0, -offset);
|
||||
section = section.slice(-offset);
|
||||
offset = 0;
|
||||
}
|
||||
const shouldSkip = section.length === 0 && type === 'startEnd';
|
||||
if (!shouldSkip) {
|
||||
yield [
|
||||
section,
|
||||
block.name,
|
||||
start + offset,
|
||||
type === 'errorMappingOnly'
|
||||
? codeFeatures_1.codeFeatures.verification
|
||||
: type === 'shorthand'
|
||||
? { ...data, __shorthandExpression: 'js' }
|
||||
: data,
|
||||
];
|
||||
}
|
||||
yield addSuffix;
|
||||
}
|
||||
}
|
||||
function* forEachInterpolationSegment(ts, setupRefs, ctx, block, originalCode, start, prefix, suffix) {
|
||||
const code = prefix + originalCode + suffix;
|
||||
let prevEnd = 0;
|
||||
for (const [name, offset, isShorthand] of forEachIdentifiers(ts, ctx, block, originalCode, code, prefix)) {
|
||||
if (isShorthand) {
|
||||
yield [code.slice(prevEnd, offset + name.length), prevEnd];
|
||||
yield `: `;
|
||||
}
|
||||
else {
|
||||
yield [code.slice(prevEnd, offset), prevEnd, prevEnd > 0 ? undefined : 'startEnd'];
|
||||
}
|
||||
if (setupRefs.has(name)) {
|
||||
yield [name, offset];
|
||||
yield `.value`;
|
||||
}
|
||||
else {
|
||||
yield ['', offset, 'errorMappingOnly']; // #1205, #1264
|
||||
if (ctx.dollarVars.has(name)) {
|
||||
yield names.dollars;
|
||||
}
|
||||
else {
|
||||
ctx.recordComponentAccess(block.name, name, start - prefix.length + offset);
|
||||
yield names.ctx;
|
||||
}
|
||||
yield `.`;
|
||||
yield [name, offset, isShorthand ? 'shorthand' : undefined];
|
||||
}
|
||||
prevEnd = offset + name.length;
|
||||
}
|
||||
if (prevEnd < code.length) {
|
||||
yield [code.slice(prevEnd), prevEnd, 'startEnd'];
|
||||
}
|
||||
}
|
||||
function* forEachIdentifiers(ts, ctx, block, originalCode, code, prefix) {
|
||||
if (utils_1.identifierRegex.test(originalCode) && !shouldIdentifierSkipped(ctx, originalCode)) {
|
||||
yield [originalCode, prefix.length, false];
|
||||
return;
|
||||
}
|
||||
const endScope = ctx.startScope();
|
||||
const ast = (0, utils_1.getTypeScriptAST)(ts, block, code);
|
||||
for (const [id, isShorthand] of forEachDeclarations(ts, ast, ast, ctx)) {
|
||||
const text = (0, shared_2.getNodeText)(ts, id, ast);
|
||||
if (shouldIdentifierSkipped(ctx, text)) {
|
||||
continue;
|
||||
}
|
||||
yield [text, (0, shared_2.getStartEnd)(ts, id, ast).start, isShorthand];
|
||||
}
|
||||
endScope();
|
||||
}
|
||||
function* forEachDeclarations(ts, node, ast, ctx) {
|
||||
if (ts.isIdentifier(node)) {
|
||||
yield [node, false];
|
||||
}
|
||||
else if (ts.isShorthandPropertyAssignment(node)) {
|
||||
yield [node.name, true];
|
||||
}
|
||||
else if (ts.isPropertyAccessExpression(node)) {
|
||||
yield* forEachDeclarations(ts, node.expression, ast, ctx);
|
||||
}
|
||||
else if (ts.isVariableDeclaration(node)) {
|
||||
ctx.declare(...(0, collectBindings_1.collectBindingNames)(ts, node.name, ast));
|
||||
yield* forEachDeclarationsInBinding(ts, node, ast, ctx);
|
||||
}
|
||||
else if (ts.isArrayBindingPattern(node) || ts.isObjectBindingPattern(node)) {
|
||||
for (const element of node.elements) {
|
||||
if (ts.isBindingElement(element)) {
|
||||
yield* forEachDeclarationsInBinding(ts, element, ast, ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {
|
||||
yield* forEachDeclarationsInFunction(ts, node, ast, ctx);
|
||||
}
|
||||
else if (ts.isObjectLiteralExpression(node)) {
|
||||
for (const prop of node.properties) {
|
||||
if (ts.isPropertyAssignment(prop)) {
|
||||
// fix https://github.com/vuejs/language-tools/issues/1176
|
||||
if (ts.isComputedPropertyName(prop.name)) {
|
||||
yield* forEachDeclarations(ts, prop.name.expression, ast, ctx);
|
||||
}
|
||||
yield* forEachDeclarations(ts, prop.initializer, ast, ctx);
|
||||
}
|
||||
// fix https://github.com/vuejs/language-tools/issues/1156
|
||||
else if (ts.isShorthandPropertyAssignment(prop)) {
|
||||
yield* forEachDeclarations(ts, prop, ast, ctx);
|
||||
}
|
||||
// fix https://github.com/vuejs/language-tools/issues/1148#issuecomment-1094378126
|
||||
else if (ts.isSpreadAssignment(prop)) {
|
||||
// TODO: cannot report "Spread types may only be created from object types.ts(2698)"
|
||||
yield* forEachDeclarations(ts, prop.expression, ast, ctx);
|
||||
}
|
||||
// fix https://github.com/vuejs/language-tools/issues/4604
|
||||
else if (ts.isFunctionLike(prop) && prop.body) {
|
||||
yield* forEachDeclarationsInFunction(ts, prop, ast, ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
// fix https://github.com/vuejs/language-tools/issues/1422
|
||||
else if (ts.isTypeNode(node)) {
|
||||
yield* forEachDeclarationsInTypeNode(ts, node);
|
||||
}
|
||||
else if (ts.isBlock(node)) {
|
||||
const endScope = ctx.startScope();
|
||||
for (const child of (0, utils_1.forEachNode)(ts, node)) {
|
||||
yield* forEachDeclarations(ts, child, ast, ctx);
|
||||
}
|
||||
endScope();
|
||||
}
|
||||
else {
|
||||
for (const child of (0, utils_1.forEachNode)(ts, node)) {
|
||||
yield* forEachDeclarations(ts, child, ast, ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
function* forEachDeclarationsInBinding(ts, node, ast, ctx) {
|
||||
if ('type' in node && node.type) {
|
||||
yield* forEachDeclarationsInTypeNode(ts, node.type);
|
||||
}
|
||||
if (!ts.isIdentifier(node.name)) {
|
||||
yield* forEachDeclarations(ts, node.name, ast, ctx);
|
||||
}
|
||||
if (node.initializer) {
|
||||
yield* forEachDeclarations(ts, node.initializer, ast, ctx);
|
||||
}
|
||||
}
|
||||
function* forEachDeclarationsInFunction(ts, node, ast, ctx) {
|
||||
const endScope = ctx.startScope();
|
||||
for (const param of node.parameters) {
|
||||
ctx.declare(...(0, collectBindings_1.collectBindingNames)(ts, param.name, ast));
|
||||
yield* forEachDeclarationsInBinding(ts, param, ast, ctx);
|
||||
}
|
||||
if (node.body) {
|
||||
yield* forEachDeclarations(ts, node.body, ast, ctx);
|
||||
}
|
||||
endScope();
|
||||
}
|
||||
function* forEachDeclarationsInTypeNode(ts, node) {
|
||||
if (ts.isTypeQueryNode(node)) {
|
||||
let id = node.exprName;
|
||||
while (!ts.isIdentifier(id)) {
|
||||
id = id.left;
|
||||
}
|
||||
yield [id, false];
|
||||
}
|
||||
else {
|
||||
for (const child of (0, utils_1.forEachNode)(ts, node)) {
|
||||
yield* forEachDeclarationsInTypeNode(ts, child);
|
||||
}
|
||||
}
|
||||
}
|
||||
function shouldIdentifierSkipped(ctx, text) {
|
||||
return ctx.scopes.some(scope => scope.has(text))
|
||||
// https://github.com/vuejs/core/blob/245230e135152900189f13a4281302de45fdcfaa/packages/compiler-core/src/transforms/transformExpression.ts#L342-L352
|
||||
|| (0, shared_1.isGloballyAllowed)(text)
|
||||
|| isLiteralWhitelisted(text)
|
||||
|| text === 'require'
|
||||
|| text.startsWith('__VLS_');
|
||||
}
|
||||
//# sourceMappingURL=interpolation.js.map
|
||||
Loaded 100 of 2411 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user