@vue-jsx-vapor/compiler 0.1.4 → 0.1.5
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 +16 -31
- package/dist/index.d.cts +0 -5
- package/dist/index.d.ts +0 -5
- package/dist/index.js +15 -30
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/index.ts
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/index.ts
|
2
2
|
var _compilervapor = require('@vue/compiler-vapor');
|
3
3
|
|
4
4
|
// src/compile.ts
|
@@ -20,7 +20,6 @@ var _parser = require('@babel/parser');
|
|
20
20
|
|
21
21
|
|
22
22
|
|
23
|
-
|
24
23
|
// src/transforms/utils.ts
|
25
24
|
|
26
25
|
|
@@ -83,14 +82,11 @@ var isConstant = (node) => {
|
|
83
82
|
}
|
84
83
|
return false;
|
85
84
|
};
|
86
|
-
function isLiteralExpressionContainer(node) {
|
87
|
-
return _optionalChain([node, 'optionalAccess', _2 => _2.type]) === "JSXExpressionContainer" && node.expression.type !== "JSXEmptyExpression" && isConstant(node.expression);
|
88
|
-
}
|
89
85
|
var EMPTY_TEXT_REGEX = /^\s*[\n\r]\s*$/;
|
90
86
|
var START_EMPTY_TEXT_REGEX = /^\s*[\n\r]/;
|
91
87
|
var END_EMPTY_TEXT_REGEX = /[\n\r]\s*$/;
|
92
88
|
function resolveJSXText(node) {
|
93
|
-
if (EMPTY_TEXT_REGEX.test(`${_optionalChain([node, 'access',
|
89
|
+
if (EMPTY_TEXT_REGEX.test(`${_optionalChain([node, 'access', _2 => _2.extra, 'optionalAccess', _3 => _3.raw])}`)) {
|
94
90
|
return "";
|
95
91
|
}
|
96
92
|
let value = node.value;
|
@@ -103,27 +99,26 @@ function resolveJSXText(node) {
|
|
103
99
|
return value;
|
104
100
|
}
|
105
101
|
function isEmptyText(node) {
|
106
|
-
return node.type === "JSXText" && EMPTY_TEXT_REGEX.test(`${_optionalChain([node, 'access',
|
102
|
+
return node.type === "JSXText" && EMPTY_TEXT_REGEX.test(`${_optionalChain([node, 'access', _4 => _4.extra, 'optionalAccess', _5 => _5.raw])}`) || node.type === "JSXExpressionContainer" && node.expression.type === "JSXEmptyExpression";
|
107
103
|
}
|
108
104
|
function resolveExpression(node, context, effect = false) {
|
105
|
+
node = _optionalChain([node, 'optionalAccess', _6 => _6.type]) === "JSXExpressionContainer" ? node.expression : node;
|
109
106
|
const isStatic = !!node && (node.type === "StringLiteral" || node.type === "JSXText" || node.type === "JSXIdentifier");
|
110
|
-
let source = !node ? "" : node.type === "JSXIdentifier" ? node.name : node.type === "StringLiteral" ? node.value : node.type === "JSXText" ? resolveJSXText(node) : node.type === "
|
111
|
-
node.expression.start,
|
112
|
-
node.expression.end
|
113
|
-
) : context.ir.source.slice(node.start, node.end);
|
107
|
+
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);
|
114
108
|
const location = node ? node.loc : null;
|
115
|
-
|
109
|
+
let ast;
|
110
|
+
if (source && !isStatic && effect && !isConstant(node)) {
|
116
111
|
source = `() => (${source})`;
|
117
112
|
}
|
118
|
-
return resolveSimpleExpression(source, isStatic, location);
|
113
|
+
return resolveSimpleExpression(source, isStatic, location, ast);
|
119
114
|
}
|
120
|
-
function resolveSimpleExpression(source, isStatic, location) {
|
115
|
+
function resolveSimpleExpression(source, isStatic, location, ast) {
|
121
116
|
const result = _compilerdom.createSimpleExpression.call(void 0,
|
122
117
|
source,
|
123
118
|
isStatic,
|
124
119
|
resolveLocation(location, source)
|
125
120
|
);
|
126
|
-
result.ast = null;
|
121
|
+
result.ast = _nullishCoalesce(ast, () => ( null));
|
127
122
|
return result;
|
128
123
|
}
|
129
124
|
function resolveLocation(location, context) {
|
@@ -417,24 +412,21 @@ var TransformContext = class _TransformContext {
|
|
417
412
|
if (this.inVOnce || expressions.length === 0) {
|
418
413
|
return this.registerOperation(...operations);
|
419
414
|
}
|
420
|
-
const ids = /* @__PURE__ */ new Set();
|
421
|
-
expressions.forEach((exp) => extractIdentifiers(ids, exp));
|
422
415
|
const existing = this.block.effect.find(
|
423
|
-
(e) =>
|
416
|
+
(e) => isSameExpression(e.expressions, expressions)
|
424
417
|
);
|
425
418
|
if (existing) {
|
426
419
|
existing.operations.push(...operations);
|
427
420
|
} else {
|
428
421
|
this.block.effect.push({
|
429
422
|
expressions,
|
430
|
-
operations
|
431
|
-
earlyCheckExps: [],
|
432
|
-
declareNames: /* @__PURE__ */ new Set(),
|
433
|
-
rewrittenNames: /* @__PURE__ */ new Set(),
|
434
|
-
inVFor: this.inVFor > 0,
|
435
|
-
identifiers: Array.from(ids)
|
423
|
+
operations
|
436
424
|
});
|
437
425
|
}
|
426
|
+
function isSameExpression(a, b) {
|
427
|
+
if (a.length !== b.length) return false;
|
428
|
+
return a.every((exp, i) => exp.content === b[i].content);
|
429
|
+
}
|
438
430
|
}
|
439
431
|
registerOperation(...node) {
|
440
432
|
this.block.operation.push(...node);
|
@@ -492,13 +484,6 @@ function transformNode(context) {
|
|
492
484
|
context.registerTemplate();
|
493
485
|
}
|
494
486
|
}
|
495
|
-
function extractIdentifiers(ids, node) {
|
496
|
-
if (node.ast) {
|
497
|
-
_compilerdom.walkIdentifiers.call(void 0, node.ast, (n) => ids.add(n.name), true);
|
498
|
-
} else if (node.ast === null) {
|
499
|
-
ids.add(node.content);
|
500
|
-
}
|
501
|
-
}
|
502
487
|
|
503
488
|
// src/transforms/transformElement.ts
|
504
489
|
|
package/dist/index.d.cts
CHANGED
@@ -272,12 +272,7 @@ interface IRDynamicInfo {
|
|
272
272
|
}
|
273
273
|
interface IREffect {
|
274
274
|
expressions: SimpleExpressionNode[];
|
275
|
-
identifiers: string[];
|
276
275
|
operations: OperationNode[];
|
277
|
-
declareNames: Set<string>;
|
278
|
-
rewrittenNames: Set<string>;
|
279
|
-
earlyCheckExps: string[];
|
280
|
-
inVFor: boolean;
|
281
276
|
}
|
282
277
|
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & Pick<U, Extract<keyof U, keyof T>>;
|
283
278
|
type HackOptions<T> = Prettify<Overwrite<T, {
|
package/dist/index.d.ts
CHANGED
@@ -272,12 +272,7 @@ interface IRDynamicInfo {
|
|
272
272
|
}
|
273
273
|
interface IREffect {
|
274
274
|
expressions: SimpleExpressionNode[];
|
275
|
-
identifiers: string[];
|
276
275
|
operations: OperationNode[];
|
277
|
-
declareNames: Set<string>;
|
278
|
-
rewrittenNames: Set<string>;
|
279
|
-
earlyCheckExps: string[];
|
280
|
-
inVFor: boolean;
|
281
276
|
}
|
282
277
|
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & Pick<U, Extract<keyof U, keyof T>>;
|
283
278
|
type HackOptions<T> = Prettify<Overwrite<T, {
|
package/dist/index.js
CHANGED
@@ -16,10 +16,9 @@ import { parse } from "@babel/parser";
|
|
16
16
|
// src/transform.ts
|
17
17
|
import {
|
18
18
|
defaultOnError,
|
19
|
-
defaultOnWarn
|
20
|
-
walkIdentifiers
|
19
|
+
defaultOnWarn
|
21
20
|
} from "@vue/compiler-dom";
|
22
|
-
import { EMPTY_OBJ, NOOP, extend, isArray
|
21
|
+
import { EMPTY_OBJ, NOOP, extend, isArray } from "@vue/shared";
|
23
22
|
|
24
23
|
// src/transforms/utils.ts
|
25
24
|
import {
|
@@ -83,9 +82,6 @@ var isConstant = (node) => {
|
|
83
82
|
}
|
84
83
|
return false;
|
85
84
|
};
|
86
|
-
function isLiteralExpressionContainer(node) {
|
87
|
-
return node?.type === "JSXExpressionContainer" && node.expression.type !== "JSXEmptyExpression" && isConstant(node.expression);
|
88
|
-
}
|
89
85
|
var EMPTY_TEXT_REGEX = /^\s*[\n\r]\s*$/;
|
90
86
|
var START_EMPTY_TEXT_REGEX = /^\s*[\n\r]/;
|
91
87
|
var END_EMPTY_TEXT_REGEX = /[\n\r]\s*$/;
|
@@ -106,24 +102,23 @@ function isEmptyText(node) {
|
|
106
102
|
return node.type === "JSXText" && EMPTY_TEXT_REGEX.test(`${node.extra?.raw}`) || node.type === "JSXExpressionContainer" && node.expression.type === "JSXEmptyExpression";
|
107
103
|
}
|
108
104
|
function resolveExpression(node, context, effect = false) {
|
105
|
+
node = node?.type === "JSXExpressionContainer" ? node.expression : node;
|
109
106
|
const isStatic = !!node && (node.type === "StringLiteral" || node.type === "JSXText" || node.type === "JSXIdentifier");
|
110
|
-
let source = !node ? "" : node.type === "JSXIdentifier" ? node.name : node.type === "StringLiteral" ? node.value : node.type === "JSXText" ? resolveJSXText(node) : node.type === "
|
111
|
-
node.expression.start,
|
112
|
-
node.expression.end
|
113
|
-
) : context.ir.source.slice(node.start, node.end);
|
107
|
+
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);
|
114
108
|
const location = node ? node.loc : null;
|
115
|
-
|
109
|
+
let ast;
|
110
|
+
if (source && !isStatic && effect && !isConstant(node)) {
|
116
111
|
source = `() => (${source})`;
|
117
112
|
}
|
118
|
-
return resolveSimpleExpression(source, isStatic, location);
|
113
|
+
return resolveSimpleExpression(source, isStatic, location, ast);
|
119
114
|
}
|
120
|
-
function resolveSimpleExpression(source, isStatic, location) {
|
115
|
+
function resolveSimpleExpression(source, isStatic, location, ast) {
|
121
116
|
const result = createSimpleExpression(
|
122
117
|
source,
|
123
118
|
isStatic,
|
124
119
|
resolveLocation(location, source)
|
125
120
|
);
|
126
|
-
result.ast = null;
|
121
|
+
result.ast = ast ?? null;
|
127
122
|
return result;
|
128
123
|
}
|
129
124
|
function resolveLocation(location, context) {
|
@@ -417,24 +412,21 @@ var TransformContext = class _TransformContext {
|
|
417
412
|
if (this.inVOnce || expressions.length === 0) {
|
418
413
|
return this.registerOperation(...operations);
|
419
414
|
}
|
420
|
-
const ids = /* @__PURE__ */ new Set();
|
421
|
-
expressions.forEach((exp) => extractIdentifiers(ids, exp));
|
422
415
|
const existing = this.block.effect.find(
|
423
|
-
(e) =>
|
416
|
+
(e) => isSameExpression(e.expressions, expressions)
|
424
417
|
);
|
425
418
|
if (existing) {
|
426
419
|
existing.operations.push(...operations);
|
427
420
|
} else {
|
428
421
|
this.block.effect.push({
|
429
422
|
expressions,
|
430
|
-
operations
|
431
|
-
earlyCheckExps: [],
|
432
|
-
declareNames: /* @__PURE__ */ new Set(),
|
433
|
-
rewrittenNames: /* @__PURE__ */ new Set(),
|
434
|
-
inVFor: this.inVFor > 0,
|
435
|
-
identifiers: Array.from(ids)
|
423
|
+
operations
|
436
424
|
});
|
437
425
|
}
|
426
|
+
function isSameExpression(a, b) {
|
427
|
+
if (a.length !== b.length) return false;
|
428
|
+
return a.every((exp, i) => exp.content === b[i].content);
|
429
|
+
}
|
438
430
|
}
|
439
431
|
registerOperation(...node) {
|
440
432
|
this.block.operation.push(...node);
|
@@ -492,13 +484,6 @@ function transformNode(context) {
|
|
492
484
|
context.registerTemplate();
|
493
485
|
}
|
494
486
|
}
|
495
|
-
function extractIdentifiers(ids, node) {
|
496
|
-
if (node.ast) {
|
497
|
-
walkIdentifiers(node.ast, (n) => ids.add(n.name), true);
|
498
|
-
} else if (node.ast === null) {
|
499
|
-
ids.add(node.content);
|
500
|
-
}
|
501
|
-
}
|
502
487
|
|
503
488
|
// src/transforms/transformElement.ts
|
504
489
|
import { extend as extend2, isBuiltInDirective, isVoidTag, makeMap as makeMap2 } from "@vue/shared";
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vue-jsx-vapor/compiler",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.5",
|
4
4
|
"description": "Vue JSX Vapor Compiler",
|
5
5
|
"type": "module",
|
6
6
|
"keywords": [
|
@@ -51,11 +51,11 @@
|
|
51
51
|
"@babel/parser": "^7.26.7",
|
52
52
|
"@babel/types": "^7.26.7",
|
53
53
|
"@vue-macros/common": "^1.10.4",
|
54
|
-
"@vue/compiler-core": "https://pkg.pr.new/vuejs/vue-vapor/@vue/compiler-core@
|
55
|
-
"@vue/compiler-dom": "https://pkg.pr.new/vuejs/vue-vapor/@vue/compiler-dom@
|
56
|
-
"@vue/compiler-vapor": "https://pkg.pr.new/vuejs/vue-vapor/@vue/compiler-vapor@
|
57
|
-
"@vue/runtime-vapor": "https://pkg.pr.new/vuejs/vue-vapor/@vue/runtime-vapor@
|
58
|
-
"@vue/shared": "https://pkg.pr.new/vuejs/vue-vapor/@vue/shared@
|
54
|
+
"@vue/compiler-core": "https://pkg.pr.new/vuejs/vue-vapor/@vue/compiler-core@6d5bc43",
|
55
|
+
"@vue/compiler-dom": "https://pkg.pr.new/vuejs/vue-vapor/@vue/compiler-dom@6d5bc43",
|
56
|
+
"@vue/compiler-vapor": "https://pkg.pr.new/vuejs/vue-vapor/@vue/compiler-vapor@6d5bc43",
|
57
|
+
"@vue/runtime-vapor": "https://pkg.pr.new/vuejs/vue-vapor/@vue/runtime-vapor@6d5bc43",
|
58
|
+
"@vue/shared": "https://pkg.pr.new/vuejs/vue-vapor/@vue/shared@6d5bc43"
|
59
59
|
},
|
60
60
|
"scripts": {
|
61
61
|
"build": "tsup",
|