@vue-jsx-vapor/compiler 2.4.0 → 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 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 = node?.type === "JSXExpressionContainer" ? node.expression : node;
172
- const isStatic = !!node && (node.type === "StringLiteral" || node.type === "JSXText" || node.type === "JSXIdentifier");
173
- let source = !node || 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);
174
- const location = node ? node.loc : null;
175
- const isResolved = node && resolvedExpressions.has(node);
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 (node && !isResolved) {
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
- node = node?.type === "JSXExpressionContainer" ? node.expression : node;
149
- const isStatic = !!node && (node.type === "StringLiteral" || node.type === "JSXText" || node.type === "JSXIdentifier");
150
- let source = !node || 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);
151
- const location = node ? node.loc : null;
152
- const isResolved = node && resolvedExpressions.has(node);
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 (node && !isResolved) {
166
+ if (!isResolved) {
161
167
  const offset = node.start - 1;
162
168
  walkIdentifiers(node, (id) => {
163
169
  if (!id.loc) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue-jsx-vapor/compiler",
3
- "version": "2.4.0",
3
+ "version": "2.4.2",
4
4
  "description": "Vue JSX Vapor Compiler",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -36,9 +36,9 @@
36
36
  "dependencies": {
37
37
  "@babel/parser": "^7.26.8",
38
38
  "@babel/types": "^7.26.8",
39
- "@vue/compiler-dom": "https://pkg.pr.new/@vue/compiler-dom@1c02a3e",
40
- "@vue/compiler-vapor": "https://pkg.pr.new/@vue/compiler-vapor@1c02a3e",
41
- "@vue/shared": "https://pkg.pr.new/@vue/shared@1c02a3e"
39
+ "@vue/compiler-dom": "https://pkg.pr.new/@vue/compiler-dom@46e707d",
40
+ "@vue/compiler-vapor": "https://pkg.pr.new/@vue/compiler-vapor@46e707d",
41
+ "@vue/shared": "https://pkg.pr.new/@vue/shared@46e707d"
42
42
  },
43
43
  "scripts": {
44
44
  "build": "tsdown",