@vue-jsx-vapor/compiler 2.4.1 → 2.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +13 -7
- package/dist/index.js +14 -8
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
@@ -137,7 +137,12 @@ function getLiteralExpressionValue(exp) {
|
|
137
137
|
}
|
138
138
|
const isConstant = (node) => {
|
139
139
|
if (!node) return false;
|
140
|
-
if (node.type === "Identifier") return node.name === "undefined";
|
140
|
+
if (node.type === "Identifier") return node.name === "undefined" || (0, __vue_shared.isGloballyAllowed)(node.name);
|
141
|
+
if ([
|
142
|
+
"JSXElement",
|
143
|
+
"JSXFragment",
|
144
|
+
"NullLiteral"
|
145
|
+
].includes(node.type)) return true;
|
141
146
|
if (node.type === "ArrayExpression") {
|
142
147
|
const { elements } = node;
|
143
148
|
return elements.every((element) => element && isConstant(element));
|
@@ -168,11 +173,12 @@ function resolveSimpleExpressionNode(exp) {
|
|
168
173
|
}
|
169
174
|
const resolvedExpressions = new WeakSet();
|
170
175
|
function resolveExpression(node, context, effect = false) {
|
171
|
-
node
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
const
|
176
|
+
if (!node) return (0, __vue_compiler_dom.createSimpleExpression)("", true);
|
177
|
+
node = (0, __vue_compiler_dom.unwrapTSNode)(node.type === "JSXExpressionContainer" ? node.expression : node);
|
178
|
+
const isStatic = node.type === "StringLiteral" || node.type === "JSXText" || node.type === "JSXIdentifier";
|
179
|
+
let source = node.type === "JSXEmptyExpression" ? "" : node.type === "JSXIdentifier" ? node.name : node.type === "StringLiteral" ? node.value : node.type === "JSXText" ? resolveJSXText(node) : node.type === "Identifier" ? node.name : context.ir.source.slice(node.start, node.end);
|
180
|
+
const location = node.loc;
|
181
|
+
const isResolved = resolvedExpressions.has(node);
|
176
182
|
if (source && !isStatic && effect && !isConstant(node)) {
|
177
183
|
source = `() => (${source})`;
|
178
184
|
if (location && node && !isResolved) {
|
@@ -180,7 +186,7 @@ function resolveExpression(node, context, effect = false) {
|
|
180
186
|
node.start -= 7;
|
181
187
|
}
|
182
188
|
}
|
183
|
-
if (
|
189
|
+
if (!isResolved) {
|
184
190
|
const offset = node.start - 1;
|
185
191
|
(0, __vue_compiler_dom.walkIdentifiers)(node, (id) => {
|
186
192
|
if (!id.loc) return;
|
package/dist/index.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { parse, parseExpression } from "@babel/parser";
|
2
2
|
import { NEWLINE, genCall, genExpression, generate } from "@vue/compiler-vapor";
|
3
3
|
import { EMPTY_OBJ, NOOP, camelize, extend, isArray, isBuiltInDirective, isGloballyAllowed, isHTMLTag, isSVGTag, isString, isVoidTag, makeMap } from "@vue/shared";
|
4
|
-
import { DOMErrorCodes, ErrorCodes, NodeTypes, createCompilerError, createDOMCompilerError, createSimpleExpression, defaultOnError, defaultOnWarn, isConstantNode, isLiteralWhitelisted, isMemberExpression, isStaticNode, isValidHTMLNesting, resolveModifiers, walkIdentifiers } from "@vue/compiler-dom";
|
4
|
+
import { DOMErrorCodes, ErrorCodes, NodeTypes, createCompilerError, createDOMCompilerError, createSimpleExpression, defaultOnError, defaultOnWarn, isConstantNode, isLiteralWhitelisted, isMemberExpression, isStaticNode, isValidHTMLNesting, resolveModifiers, unwrapTSNode, walkIdentifiers } from "@vue/compiler-dom";
|
5
5
|
import { isLiteral, jsxClosingFragment, jsxExpressionContainer, jsxFragment, jsxOpeningFragment } from "@babel/types";
|
6
6
|
|
7
7
|
//#region src/ir/component.ts
|
@@ -114,7 +114,12 @@ function getLiteralExpressionValue(exp) {
|
|
114
114
|
}
|
115
115
|
const isConstant = (node) => {
|
116
116
|
if (!node) return false;
|
117
|
-
if (node.type === "Identifier") return node.name === "undefined";
|
117
|
+
if (node.type === "Identifier") return node.name === "undefined" || isGloballyAllowed(node.name);
|
118
|
+
if ([
|
119
|
+
"JSXElement",
|
120
|
+
"JSXFragment",
|
121
|
+
"NullLiteral"
|
122
|
+
].includes(node.type)) return true;
|
118
123
|
if (node.type === "ArrayExpression") {
|
119
124
|
const { elements } = node;
|
120
125
|
return elements.every((element) => element && isConstant(element));
|
@@ -145,11 +150,12 @@ function resolveSimpleExpressionNode(exp) {
|
|
145
150
|
}
|
146
151
|
const resolvedExpressions = new WeakSet();
|
147
152
|
function resolveExpression(node, context, effect = false) {
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
const
|
153
|
+
if (!node) return createSimpleExpression("", true);
|
154
|
+
node = unwrapTSNode(node.type === "JSXExpressionContainer" ? node.expression : node);
|
155
|
+
const isStatic = node.type === "StringLiteral" || node.type === "JSXText" || node.type === "JSXIdentifier";
|
156
|
+
let source = node.type === "JSXEmptyExpression" ? "" : node.type === "JSXIdentifier" ? node.name : node.type === "StringLiteral" ? node.value : node.type === "JSXText" ? resolveJSXText(node) : node.type === "Identifier" ? node.name : context.ir.source.slice(node.start, node.end);
|
157
|
+
const location = node.loc;
|
158
|
+
const isResolved = resolvedExpressions.has(node);
|
153
159
|
if (source && !isStatic && effect && !isConstant(node)) {
|
154
160
|
source = `() => (${source})`;
|
155
161
|
if (location && node && !isResolved) {
|
@@ -157,7 +163,7 @@ function resolveExpression(node, context, effect = false) {
|
|
157
163
|
node.start -= 7;
|
158
164
|
}
|
159
165
|
}
|
160
|
-
if (
|
166
|
+
if (!isResolved) {
|
161
167
|
const offset = node.start - 1;
|
162
168
|
walkIdentifiers(node, (id) => {
|
163
169
|
if (!id.loc) return;
|