@ja-platform/parser-expressions 0.0.0-dev-20261019214152
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/README.md +112 -0
- package/dist/@types/CombinedParser.d.ts +11 -0
- package/dist/@types/ExpressionParser.d.ts +12 -0
- package/dist/@types/code-parsers/CodeParser.d.ts +25 -0
- package/dist/@types/code-parsers/JavaScriptParser.d.ts +18 -0
- package/dist/@types/definitions/ValidationContext.d.ts +8 -0
- package/dist/@types/expressions/AbstractExpression.d.ts +42 -0
- package/dist/@types/expressions/EvaluatedExpression.d.ts +34 -0
- package/dist/@types/expressions/constant/ConstantExpression.d.ts +28 -0
- package/dist/@types/expressions/function/FunctionExpression.d.ts +37 -0
- package/dist/@types/expressions/index.d.ts +8 -0
- package/dist/@types/expressions/shorthand/FormatShorthandExpression.d.ts +31 -0
- package/dist/@types/expressions/shorthand/ShorthandExpression.d.ts +42 -0
- package/dist/@types/expressions/text/AbstractFormatExpression.d.ts +43 -0
- package/dist/@types/expressions/text/FormatStringExpression.d.ts +18 -0
- package/dist/@types/index.d.ts +9 -0
- package/dist/@types/tokens/AbstractToken.d.ts +12 -0
- package/dist/@types/tokens/code/CodeToken.d.ts +142 -0
- package/dist/@types/tokens/code/IdentifierToken.d.ts +12 -0
- package/dist/@types/tokens/code/JSToken.d.ts +31 -0
- package/dist/@types/tokens/code/PrefixToken.d.ts +9 -0
- package/dist/@types/tokens/index.d.ts +8 -0
- package/dist/@types/tokens/text/PlaceholderToken.d.ts +12 -0
- package/dist/@types/tokens/text/TextToken.d.ts +12 -0
- package/dist/@types/utils/parserUtils.d.ts +7 -0
- package/dist/@types/utils/tokenUtils.d.ts +11 -0
- package/dist/@types/utils/valueFormatting.d.ts +9 -0
- package/dist/CombinedParser.js +24 -0
- package/dist/CombinedParser.js.map +1 -0
- package/dist/ExpressionParser.js +20 -0
- package/dist/ExpressionParser.js.map +1 -0
- package/dist/code-parsers/CodeParser.js +45 -0
- package/dist/code-parsers/CodeParser.js.map +1 -0
- package/dist/code-parsers/JavaScriptParser.js +56 -0
- package/dist/code-parsers/JavaScriptParser.js.map +1 -0
- package/dist/definitions/ValidationContext.js +3 -0
- package/dist/definitions/ValidationContext.js.map +1 -0
- package/dist/expressions/AbstractExpression.js +47 -0
- package/dist/expressions/AbstractExpression.js.map +1 -0
- package/dist/expressions/EvaluatedExpression.js +102 -0
- package/dist/expressions/EvaluatedExpression.js.map +1 -0
- package/dist/expressions/constant/ConstantExpression.js +53 -0
- package/dist/expressions/constant/ConstantExpression.js.map +1 -0
- package/dist/expressions/function/FunctionExpression.js +79 -0
- package/dist/expressions/function/FunctionExpression.js.map +1 -0
- package/dist/expressions/index.js +25 -0
- package/dist/expressions/index.js.map +1 -0
- package/dist/expressions/shorthand/FormatShorthandExpression.js +60 -0
- package/dist/expressions/shorthand/FormatShorthandExpression.js.map +1 -0
- package/dist/expressions/shorthand/ShorthandExpression.js +90 -0
- package/dist/expressions/shorthand/ShorthandExpression.js.map +1 -0
- package/dist/expressions/text/AbstractFormatExpression.js +178 -0
- package/dist/expressions/text/AbstractFormatExpression.js.map +1 -0
- package/dist/expressions/text/FormatStringExpression.js +44 -0
- package/dist/expressions/text/FormatStringExpression.js.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/tokens/AbstractToken.js +22 -0
- package/dist/tokens/AbstractToken.js.map +1 -0
- package/dist/tokens/code/CodeToken.js +33 -0
- package/dist/tokens/code/CodeToken.js.map +1 -0
- package/dist/tokens/code/IdentifierToken.js +28 -0
- package/dist/tokens/code/IdentifierToken.js.map +1 -0
- package/dist/tokens/code/JSToken.js +251 -0
- package/dist/tokens/code/JSToken.js.map +1 -0
- package/dist/tokens/code/PrefixToken.js +24 -0
- package/dist/tokens/code/PrefixToken.js.map +1 -0
- package/dist/tokens/index.js +31 -0
- package/dist/tokens/index.js.map +1 -0
- package/dist/tokens/text/PlaceholderToken.js +25 -0
- package/dist/tokens/text/PlaceholderToken.js.map +1 -0
- package/dist/tokens/text/TextToken.js +28 -0
- package/dist/tokens/text/TextToken.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/utils/parserUtils.js +19 -0
- package/dist/utils/parserUtils.js.map +1 -0
- package/dist/utils/tokenUtils.js +43 -0
- package/dist/utils/tokenUtils.js.map +1 -0
- package/dist/utils/valueFormatting.js +34 -0
- package/dist/utils/valueFormatting.js.map +1 -0
- package/package.json +40 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.JSToken = void 0;
|
|
7
|
+
const traverse_1 = __importDefault(require("@babel/traverse"));
|
|
8
|
+
const types_1 = require("@babel/types");
|
|
9
|
+
const CodeToken_1 = require("./CodeToken");
|
|
10
|
+
const TextToken_1 = require("../text/TextToken");
|
|
11
|
+
const CodeParser_1 = require("../../code-parsers/CodeParser");
|
|
12
|
+
const JavaScriptParser_1 = require("../../code-parsers/JavaScriptParser");
|
|
13
|
+
/**
|
|
14
|
+
* JavaScript stays as one source token containing Babel's tree, without a second expression tree.
|
|
15
|
+
* Babel node offsets are relative to this token's source; start locates it in the surrounding source.
|
|
16
|
+
*/
|
|
17
|
+
class JSToken extends CodeToken_1.CodeToken {
|
|
18
|
+
constructor(source, start = 0) {
|
|
19
|
+
super(source, start);
|
|
20
|
+
const parsed = CodeParser_1.CodeParser.getInstance().parse(source, JSToken.parser);
|
|
21
|
+
this.ast = parsed.ast;
|
|
22
|
+
this.code = parsed.code;
|
|
23
|
+
this.freeIdentifiers = Object.freeze(parsed.freeIdentifiers);
|
|
24
|
+
this.lexemes = parsed.lexemes;
|
|
25
|
+
Object.freeze(this);
|
|
26
|
+
}
|
|
27
|
+
get arguments() {
|
|
28
|
+
return this.call().arguments;
|
|
29
|
+
}
|
|
30
|
+
functionName() {
|
|
31
|
+
return this.sourceOf(this.call().callee);
|
|
32
|
+
}
|
|
33
|
+
isCallExpression() {
|
|
34
|
+
return this.ast.type === 'CallExpression' || this.ast.type === 'OptionalCallExpression';
|
|
35
|
+
}
|
|
36
|
+
isReferenceExpression() {
|
|
37
|
+
return ['Identifier', 'MemberExpression', 'OptionalMemberExpression'].includes(this.ast.type);
|
|
38
|
+
}
|
|
39
|
+
referencePath() {
|
|
40
|
+
const normalize = (node) => {
|
|
41
|
+
if (node.type === 'Identifier')
|
|
42
|
+
return [node.name];
|
|
43
|
+
if (node.type !== 'MemberExpression')
|
|
44
|
+
return null;
|
|
45
|
+
const parent = normalize(node.object);
|
|
46
|
+
if (parent == null)
|
|
47
|
+
return null;
|
|
48
|
+
const key = node.property;
|
|
49
|
+
if (!node.computed && key.type === 'Identifier')
|
|
50
|
+
return [...parent, key.name];
|
|
51
|
+
if (node.computed &&
|
|
52
|
+
(key.type === 'StringLiteral' || (key.type === 'NumericLiteral' && Number.isFinite(key.value)))) {
|
|
53
|
+
return [...parent, key.value];
|
|
54
|
+
}
|
|
55
|
+
if (node.computed &&
|
|
56
|
+
key.type === 'UnaryExpression' &&
|
|
57
|
+
key.operator === '-' &&
|
|
58
|
+
key.argument.type === 'NumericLiteral' &&
|
|
59
|
+
Number.isFinite(key.argument.value)) {
|
|
60
|
+
return [...parent, -key.argument.value];
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
};
|
|
64
|
+
const path = normalize(this.ast);
|
|
65
|
+
return path == null ? null : Object.freeze(path);
|
|
66
|
+
}
|
|
67
|
+
withName(name) {
|
|
68
|
+
const callee = this.call().callee;
|
|
69
|
+
return this.replace([{ start: callee.start, end: callee.end, text: name }]);
|
|
70
|
+
}
|
|
71
|
+
withArguments(args) {
|
|
72
|
+
const call = this.call();
|
|
73
|
+
let edits;
|
|
74
|
+
// Replacing arguments individually retains the original separators and comments. If the count
|
|
75
|
+
// changes, replace the entire argument list so there are no leftover commas or old arguments.
|
|
76
|
+
if (args.length === call.arguments.length) {
|
|
77
|
+
edits = call.arguments.map((argument, index) => ({
|
|
78
|
+
start: argument.start,
|
|
79
|
+
end: argument.end,
|
|
80
|
+
text: args[index]
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
const open = this.punctuationAfter('(', call.callee.end);
|
|
85
|
+
edits = [{ start: open + 1, end: call.end - 1, text: args.join(', ') }];
|
|
86
|
+
}
|
|
87
|
+
return this.replace(edits);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Rewrite unbound references and direct calls, retaining scopes, property names and source trivia.
|
|
91
|
+
* Return null to leave a reference unchanged. Replacement source is not visited again.
|
|
92
|
+
*/
|
|
93
|
+
rewriteReferences(rewrite) {
|
|
94
|
+
const edits = [];
|
|
95
|
+
const render = (start, end) => {
|
|
96
|
+
let source = this.source.slice(start, end);
|
|
97
|
+
for (const edit of [...edits].sort((a, b) => b.start - a.start)) {
|
|
98
|
+
if (edit.start >= start && edit.end <= end) {
|
|
99
|
+
source = source.slice(0, edit.start - start) + edit.text + source.slice(edit.end - start);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return source;
|
|
103
|
+
};
|
|
104
|
+
const replacementSource = (replacement, parent) => {
|
|
105
|
+
var _a;
|
|
106
|
+
let javascript;
|
|
107
|
+
if (replacement instanceof JSToken) {
|
|
108
|
+
javascript = replacement;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
javascript = new JSToken(replacement.code);
|
|
112
|
+
}
|
|
113
|
+
let source = javascript.code;
|
|
114
|
+
// A replacement must keep its precedence in a larger expression. Atomic values and calls
|
|
115
|
+
// need no wrapper; compound expressions do, unless their source is already parenthesized.
|
|
116
|
+
const atomic = [
|
|
117
|
+
'Identifier',
|
|
118
|
+
'MemberExpression',
|
|
119
|
+
'OptionalMemberExpression',
|
|
120
|
+
'CallExpression',
|
|
121
|
+
'OptionalCallExpression',
|
|
122
|
+
'StringLiteral',
|
|
123
|
+
'NumericLiteral',
|
|
124
|
+
'BooleanLiteral',
|
|
125
|
+
'NullLiteral',
|
|
126
|
+
'BigIntLiteral',
|
|
127
|
+
'RegExpLiteral',
|
|
128
|
+
'TemplateLiteral',
|
|
129
|
+
'ThisExpression'
|
|
130
|
+
];
|
|
131
|
+
const numericMember = javascript.ast.type === 'NumericLiteral' &&
|
|
132
|
+
(parent.type === 'MemberExpression' || parent.type === 'OptionalMemberExpression');
|
|
133
|
+
const constructorCallee = parent.type === 'NewExpression' && !['Identifier', 'MemberExpression'].includes(javascript.ast.type);
|
|
134
|
+
if ((!atomic.includes(javascript.ast.type) || numericMember || constructorCallee) &&
|
|
135
|
+
!((_a = javascript.ast.extra) === null || _a === void 0 ? void 0 : _a.parenthesized)) {
|
|
136
|
+
source = `(${source})`;
|
|
137
|
+
}
|
|
138
|
+
return source;
|
|
139
|
+
};
|
|
140
|
+
const replaceCall = (path) => {
|
|
141
|
+
const node = path.node;
|
|
142
|
+
if (node.callee.type === 'Identifier' && !path.scope.hasBinding(node.callee.name, true)) {
|
|
143
|
+
const args = node.arguments.map((argument) => {
|
|
144
|
+
var _a;
|
|
145
|
+
let start = argument.start;
|
|
146
|
+
if ((_a = argument.extra) === null || _a === void 0 ? void 0 : _a.parenthesized) {
|
|
147
|
+
start = argument.extra.parenStart;
|
|
148
|
+
}
|
|
149
|
+
const source = render(start, start + this.sourceOf(argument).length);
|
|
150
|
+
let token;
|
|
151
|
+
if (argument.type === 'SpreadElement') {
|
|
152
|
+
token = new TextToken_1.TextToken(source, this.start + start);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
token = new JSToken(source, this.start + start);
|
|
156
|
+
}
|
|
157
|
+
return token;
|
|
158
|
+
});
|
|
159
|
+
const replacement = rewrite({ name: node.callee.name, isCall: true, arguments: args });
|
|
160
|
+
if (replacement) {
|
|
161
|
+
// Calls are visited after their children. Their argument tokens include nested edits,
|
|
162
|
+
// which are folded into the call replacement to keep the final edits from overlapping.
|
|
163
|
+
for (let index = edits.length - 1; index >= 0; index--) {
|
|
164
|
+
if (edits[index].start >= node.start && edits[index].end <= node.end) {
|
|
165
|
+
edits.splice(index, 1);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
edits.push({ start: node.start, end: node.end, text: replacementSource(replacement, path.parent) });
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
(0, traverse_1.default)((0, types_1.file)((0, types_1.program)([(0, types_1.expressionStatement)(this.ast)])), {
|
|
173
|
+
ReferencedIdentifier: (path) => {
|
|
174
|
+
const parent = path.parent;
|
|
175
|
+
const isCallee = (parent.type === 'CallExpression' || parent.type === 'OptionalCallExpression') && parent.callee === path.node;
|
|
176
|
+
if (!isCallee && !path.scope.hasBinding(path.node.name, true)) {
|
|
177
|
+
const replacement = rewrite({ name: path.node.name, isCall: false, arguments: [] });
|
|
178
|
+
if (replacement) {
|
|
179
|
+
let text = replacementSource(replacement, parent);
|
|
180
|
+
if (parent.type === 'ObjectProperty' && parent.shorthand) {
|
|
181
|
+
text = `${path.node.name}: ${text}`;
|
|
182
|
+
}
|
|
183
|
+
edits.push({ start: path.node.start, end: path.node.end, text });
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
CallExpression: { exit: replaceCall },
|
|
188
|
+
OptionalCallExpression: { exit: replaceCall }
|
|
189
|
+
});
|
|
190
|
+
return this.replace(edits);
|
|
191
|
+
}
|
|
192
|
+
call() {
|
|
193
|
+
const node = this.ast;
|
|
194
|
+
if (node.type !== 'CallExpression' && node.type !== 'OptionalCallExpression')
|
|
195
|
+
throw new Error('Only a call expression has a call target and argument list.');
|
|
196
|
+
return node;
|
|
197
|
+
}
|
|
198
|
+
replace(edits) {
|
|
199
|
+
let source = this.source;
|
|
200
|
+
// Apply edits from right to left so earlier source offsets stay valid.
|
|
201
|
+
for (const edit of [...edits].sort((a, b) => b.start - a.start))
|
|
202
|
+
source = source.slice(0, edit.start) + edit.text + source.slice(edit.end);
|
|
203
|
+
return new JSToken(source, this.start);
|
|
204
|
+
}
|
|
205
|
+
sourceOf(node) {
|
|
206
|
+
var _a;
|
|
207
|
+
let start = node.start;
|
|
208
|
+
let end = node.end;
|
|
209
|
+
if ((_a = node.extra) === null || _a === void 0 ? void 0 : _a.parenthesized) {
|
|
210
|
+
start = node.extra.parenStart;
|
|
211
|
+
}
|
|
212
|
+
// Babel records a parenthesized expression's opening offset separately. Find its matching
|
|
213
|
+
// closing token to include the complete wrapper when reusing it as an argument.
|
|
214
|
+
if (start !== node.start) {
|
|
215
|
+
let depth = 0;
|
|
216
|
+
let closed = false;
|
|
217
|
+
for (const token of this.lexemes) {
|
|
218
|
+
if (token.start >= start) {
|
|
219
|
+
const text = this.source.slice(token.start, token.end);
|
|
220
|
+
if (text === '(') {
|
|
221
|
+
depth++;
|
|
222
|
+
}
|
|
223
|
+
else if (text === ')') {
|
|
224
|
+
depth--;
|
|
225
|
+
if (depth === 0) {
|
|
226
|
+
end = token.end;
|
|
227
|
+
closed = true;
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (!closed) {
|
|
234
|
+
throw new SyntaxError('Expected a closing parenthesis.');
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return this.source.slice(start, end);
|
|
238
|
+
}
|
|
239
|
+
punctuationAfter(text, start) {
|
|
240
|
+
const token = this.lexemes.find((token) => token.start >= start && this.source.slice(token.start, token.end) === text);
|
|
241
|
+
if (!token)
|
|
242
|
+
throw new SyntaxError(`Expected ${text} after offset ${start}.`);
|
|
243
|
+
return token.start;
|
|
244
|
+
}
|
|
245
|
+
clone() {
|
|
246
|
+
return new JSToken(this.source, this.start);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
exports.JSToken = JSToken;
|
|
250
|
+
JSToken.parser = new JavaScriptParser_1.JavaScriptParser();
|
|
251
|
+
//# sourceMappingURL=JSToken.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JSToken.js","sourceRoot":"","sources":["../../../src/tokens/code/JSToken.ts"],"names":[],"mappings":";;;;;;AAAA,+DAAqD;AACrD,wCAQsB;AACtB,2CAAsE;AAEtE,iDAA8C;AAC9C,8DAA2D;AAC3D,0EAAuE;AAEvE;;;GAGG;AACH,aAAqB,SAAQ,qBAA8C;IAOzE,YAAY,MAAc,EAAE,KAAK,GAAG,CAAC;QACnC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QACrB,MAAM,MAAM,GAAG,uBAAU,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QACtE,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;QAC7D,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC,SAAS,CAAC;IAC/B,CAAC;IAED,YAAY;QACV,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;IAED,gBAAgB;QACd,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,gBAAgB,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,wBAAwB,CAAC;IAC1F,CAAC;IAED,qBAAqB;QACnB,OAAO,CAAC,YAAY,EAAE,kBAAkB,EAAE,0BAA0B,CAAC,CAAC,QAAQ,CAAC,IAAI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AAI,iBAAiB,KAAK,GAAG,CAAC,CAAC;QAC7E,OAAO,KAAK,CAAC,KAAK,CAAC;IACrB,CAAC;IAED,KAAK;QACH,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;IAC9C,CAAC;CACF;;AAxPyB,cAAM,GAAG,IAAI,mCAAgB,EAAE,CAAC","sourcesContent":["import traverse, { NodePath } from '@babel/traverse';\nimport {\n Expression,\n Node,\n CallExpression,\n OptionalCallExpression,\n file,\n program,\n expressionStatement\n} from '@babel/types';\nimport { CodeToken, CodeReference, ReferencePath } from './CodeToken';\nimport { AbstractToken } from '../AbstractToken';\nimport { TextToken } from '../text/TextToken';\nimport { CodeParser } from '../../code-parsers/CodeParser';\nimport { JavaScriptParser } from '../../code-parsers/JavaScriptParser';\n\n/**\n * JavaScript stays as one source token containing Babel's tree, without a second expression tree.\n * Babel node offsets are relative to this token's source; start locates it in the surrounding source.\n */\nexport class JSToken extends CodeToken<CallExpression['arguments'][number]> {\n private static readonly parser = new JavaScriptParser();\n readonly ast: Expression;\n readonly code: string;\n readonly freeIdentifiers: readonly string[];\n private readonly lexemes: readonly { start: number; end: number }[];\n\n constructor(source: string, start = 0) {\n super(source, start);\n const parsed = CodeParser.getInstance().parse(source, JSToken.parser);\n this.ast = parsed.ast;\n this.code = parsed.code;\n this.freeIdentifiers = Object.freeze(parsed.freeIdentifiers);\n this.lexemes = parsed.lexemes;\n Object.freeze(this);\n }\n\n get arguments(): CallExpression['arguments'] {\n return this.call().arguments;\n }\n\n functionName(): string {\n return this.sourceOf(this.call().callee);\n }\n\n isCallExpression(): boolean {\n return this.ast.type === 'CallExpression' || this.ast.type === 'OptionalCallExpression';\n }\n\n isReferenceExpression(): boolean {\n return ['Identifier', 'MemberExpression', 'OptionalMemberExpression'].includes(this.ast.type);\n }\n\n referencePath(): ReferencePath | null {\n const normalize = (node: Node): ReferencePath | null => {\n if (node.type === 'Identifier') return [node.name];\n if (node.type !== 'MemberExpression') return null;\n const parent = normalize(node.object);\n if (parent == null) return null;\n const key = node.property;\n if (!node.computed && key.type === 'Identifier') return [...parent, key.name];\n if (\n node.computed &&\n (key.type === 'StringLiteral' || (key.type === 'NumericLiteral' && Number.isFinite(key.value)))\n ) {\n return [...parent, key.value];\n }\n if (\n node.computed &&\n key.type === 'UnaryExpression' &&\n key.operator === '-' &&\n key.argument.type === 'NumericLiteral' &&\n Number.isFinite(key.argument.value)\n ) {\n return [...parent, -key.argument.value];\n }\n return null;\n };\n const path = normalize(this.ast);\n return path == null ? null : Object.freeze(path);\n }\n\n withName(name: string): JSToken {\n const callee = this.call().callee;\n return this.replace([{ start: callee.start, end: callee.end, text: name }]);\n }\n\n withArguments(args: readonly string[]): JSToken {\n const call = this.call();\n let edits: { start: number; end: number; text: string }[];\n // Replacing arguments individually retains the original separators and comments. If the count\n // changes, replace the entire argument list so there are no leftover commas or old arguments.\n if (args.length === call.arguments.length) {\n edits = call.arguments.map((argument, index) => ({\n start: argument.start,\n end: argument.end,\n text: args[index]\n }));\n } else {\n const open = this.punctuationAfter('(', call.callee.end);\n edits = [{ start: open + 1, end: call.end - 1, text: args.join(', ') }];\n }\n return this.replace(edits);\n }\n\n /**\n * Rewrite unbound references and direct calls, retaining scopes, property names and source trivia.\n * Return null to leave a reference unchanged. Replacement source is not visited again.\n */\n rewriteReferences(rewrite: (reference: CodeReference) => CodeToken | null): JSToken {\n const edits: { start: number; end: number; text: string }[] = [];\n const render = (start: number, end: number): string => {\n let source = this.source.slice(start, end);\n for (const edit of [...edits].sort((a, b) => b.start - a.start)) {\n if (edit.start >= start && edit.end <= end) {\n source = source.slice(0, edit.start - start) + edit.text + source.slice(edit.end - start);\n }\n }\n return source;\n };\n const replacementSource = (replacement: CodeToken, parent: Node): string => {\n let javascript: JSToken;\n if (replacement instanceof JSToken) {\n javascript = replacement;\n } else {\n javascript = new JSToken(replacement.code);\n }\n let source = javascript.code;\n // A replacement must keep its precedence in a larger expression. Atomic values and calls\n // need no wrapper; compound expressions do, unless their source is already parenthesized.\n const atomic = [\n 'Identifier',\n 'MemberExpression',\n 'OptionalMemberExpression',\n 'CallExpression',\n 'OptionalCallExpression',\n 'StringLiteral',\n 'NumericLiteral',\n 'BooleanLiteral',\n 'NullLiteral',\n 'BigIntLiteral',\n 'RegExpLiteral',\n 'TemplateLiteral',\n 'ThisExpression'\n ];\n const numericMember =\n javascript.ast.type === 'NumericLiteral' &&\n (parent.type === 'MemberExpression' || parent.type === 'OptionalMemberExpression');\n const constructorCallee =\n parent.type === 'NewExpression' && !['Identifier', 'MemberExpression'].includes(javascript.ast.type);\n if (\n (!atomic.includes(javascript.ast.type) || numericMember || constructorCallee) &&\n !javascript.ast.extra?.parenthesized\n ) {\n source = `(${source})`;\n }\n return source;\n };\n const replaceCall = (path: NodePath<CallExpression | OptionalCallExpression>): void => {\n const node = path.node;\n if (node.callee.type === 'Identifier' && !path.scope.hasBinding(node.callee.name, true)) {\n const args = node.arguments.map((argument): AbstractToken => {\n let start = argument.start;\n if (argument.extra?.parenthesized) {\n start = argument.extra.parenStart as number;\n }\n const source = render(start, start + this.sourceOf(argument).length);\n let token: AbstractToken;\n if (argument.type === 'SpreadElement') {\n token = new TextToken(source, this.start + start);\n } else {\n token = new JSToken(source, this.start + start);\n }\n return token;\n });\n const replacement = rewrite({ name: node.callee.name, isCall: true, arguments: args });\n if (replacement) {\n // Calls are visited after their children. Their argument tokens include nested edits,\n // which are folded into the call replacement to keep the final edits from overlapping.\n for (let index = edits.length - 1; index >= 0; index--) {\n if (edits[index].start >= node.start && edits[index].end <= node.end) {\n edits.splice(index, 1);\n }\n }\n edits.push({ start: node.start, end: node.end, text: replacementSource(replacement, path.parent) });\n }\n }\n };\n traverse(file(program([expressionStatement(this.ast)])), {\n ReferencedIdentifier: (path) => {\n const parent = path.parent;\n const isCallee =\n (parent.type === 'CallExpression' || parent.type === 'OptionalCallExpression') && parent.callee === path.node;\n if (!isCallee && !path.scope.hasBinding(path.node.name, true)) {\n const replacement = rewrite({ name: path.node.name, isCall: false, arguments: [] });\n if (replacement) {\n let text = replacementSource(replacement, parent);\n if (parent.type === 'ObjectProperty' && parent.shorthand) {\n text = `${path.node.name}: ${text}`;\n }\n edits.push({ start: path.node.start, end: path.node.end, text });\n }\n }\n },\n CallExpression: { exit: replaceCall },\n OptionalCallExpression: { exit: replaceCall }\n });\n return this.replace(edits);\n }\n\n private call(): CallExpression | OptionalCallExpression {\n const node = this.ast;\n if (node.type !== 'CallExpression' && node.type !== 'OptionalCallExpression')\n throw new Error('Only a call expression has a call target and argument list.');\n return node;\n }\n\n private replace(edits: readonly { start: number; end: number; text: string }[]): JSToken {\n let source = this.source;\n // Apply edits from right to left so earlier source offsets stay valid.\n for (const edit of [...edits].sort((a, b) => b.start - a.start))\n source = source.slice(0, edit.start) + edit.text + source.slice(edit.end);\n return new JSToken(source, this.start);\n }\n\n sourceOf(node: Node): string {\n let start = node.start;\n let end = node.end;\n if (node.extra?.parenthesized) {\n start = node.extra.parenStart as number;\n }\n // Babel records a parenthesized expression's opening offset separately. Find its matching\n // closing token to include the complete wrapper when reusing it as an argument.\n if (start !== node.start) {\n let depth = 0;\n let closed = false;\n for (const token of this.lexemes) {\n if (token.start >= start) {\n const text = this.source.slice(token.start, token.end);\n if (text === '(') {\n depth++;\n } else if (text === ')') {\n depth--;\n if (depth === 0) {\n end = token.end;\n closed = true;\n break;\n }\n }\n }\n }\n if (!closed) {\n throw new SyntaxError('Expected a closing parenthesis.');\n }\n }\n return this.source.slice(start, end);\n }\n\n punctuationAfter(text: string, start: number): number {\n const token = this.lexemes.find(\n (token) => token.start >= start && this.source.slice(token.start, token.end) === text\n );\n if (!token) throw new SyntaxError(`Expected ${text} after offset ${start}.`);\n return token.start;\n }\n\n clone(): JSToken {\n return new JSToken(this.source, this.start);\n }\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PrefixToken = exports.FUNCTION_PREFIX = void 0;
|
|
4
|
+
const AbstractToken_1 = require("../AbstractToken");
|
|
5
|
+
const IdentifierToken_1 = require("./IdentifierToken");
|
|
6
|
+
exports.FUNCTION_PREFIX = '$:';
|
|
7
|
+
class PrefixToken extends AbstractToken_1.AbstractToken {
|
|
8
|
+
constructor(start = 0, source = exports.FUNCTION_PREFIX) {
|
|
9
|
+
super(start);
|
|
10
|
+
this.source = source;
|
|
11
|
+
Object.freeze(this);
|
|
12
|
+
}
|
|
13
|
+
raw() {
|
|
14
|
+
return this.source;
|
|
15
|
+
}
|
|
16
|
+
isValid() {
|
|
17
|
+
return this.source.endsWith(':') && IdentifierToken_1.IdentifierToken.isValid(this.source.slice(0, -1));
|
|
18
|
+
}
|
|
19
|
+
clone() {
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.PrefixToken = PrefixToken;
|
|
24
|
+
//# sourceMappingURL=PrefixToken.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrefixToken.js","sourceRoot":"","sources":["../../../src/tokens/code/PrefixToken.ts"],"names":[],"mappings":";;;AAAA,oDAAiD;AACjD,uDAAoD;AAEvC,QAAA,eAAe,GAAG,IAAI,CAAC;AAEpC,iBAAyB,SAAQ,6BAAa;IAC5C,YACE,KAAK,GAAG,CAAC,EACA,MAAM,GAAG,QAAA,eAAe;QAEjC,KAAK,CAAC,KAAK,CAAC,CAAC;sBAFJ,MAAM;QAGf,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;IAED,GAAG;QACD,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,iCAAe,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IACxF,CAAC;IAED,KAAK;QACH,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["import { AbstractToken } from '../AbstractToken';\nimport { IdentifierToken } from './IdentifierToken';\n\nexport const FUNCTION_PREFIX = '$:';\n\nexport class PrefixToken extends AbstractToken {\n constructor(\n start = 0,\n readonly source = FUNCTION_PREFIX\n ) {\n super(start);\n Object.freeze(this);\n }\n\n raw(): string {\n return this.source;\n }\n\n isValid(): boolean {\n return this.source.endsWith(':') && IdentifierToken.isValid(this.source.slice(0, -1));\n }\n\n clone(): this {\n return this;\n }\n}\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.leadingTrivia = exports.hasFunctionPrefix = exports.javascriptToken = exports.codeToken = exports.stringify = void 0;
|
|
18
|
+
__exportStar(require("./AbstractToken"), exports);
|
|
19
|
+
__exportStar(require("./text/TextToken"), exports);
|
|
20
|
+
__exportStar(require("./code/JSToken"), exports);
|
|
21
|
+
__exportStar(require("./code/PrefixToken"), exports);
|
|
22
|
+
__exportStar(require("./code/IdentifierToken"), exports);
|
|
23
|
+
__exportStar(require("./text/PlaceholderToken"), exports);
|
|
24
|
+
__exportStar(require("./code/CodeToken"), exports);
|
|
25
|
+
var tokenUtils_1 = require("../utils/tokenUtils");
|
|
26
|
+
Object.defineProperty(exports, "stringify", { enumerable: true, get: function () { return tokenUtils_1.stringify; } });
|
|
27
|
+
Object.defineProperty(exports, "codeToken", { enumerable: true, get: function () { return tokenUtils_1.codeToken; } });
|
|
28
|
+
Object.defineProperty(exports, "javascriptToken", { enumerable: true, get: function () { return tokenUtils_1.javascriptToken; } });
|
|
29
|
+
Object.defineProperty(exports, "hasFunctionPrefix", { enumerable: true, get: function () { return tokenUtils_1.hasFunctionPrefix; } });
|
|
30
|
+
Object.defineProperty(exports, "leadingTrivia", { enumerable: true, get: function () { return tokenUtils_1.leadingTrivia; } });
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tokens/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,mDAAiC;AACjC,iDAA+B;AAC/B,qDAAmC;AACnC,yDAAuC;AACvC,0DAAwC;AACxC,mDAAiC;AACjC,kDAA8G;AAArG,uGAAA,SAAS,OAAA;AAAE,uGAAA,SAAS,OAAA;AAAE,6GAAA,eAAe,OAAA;AAAE,+GAAA,iBAAiB,OAAA;AAAE,2GAAA,aAAa,OAAA","sourcesContent":["export * from './AbstractToken';\nexport * from './text/TextToken';\nexport * from './code/JSToken';\nexport * from './code/PrefixToken';\nexport * from './code/IdentifierToken';\nexport * from './text/PlaceholderToken';\nexport * from './code/CodeToken';\nexport { stringify, codeToken, javascriptToken, hasFunctionPrefix, leadingTrivia } from '../utils/tokenUtils';\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PlaceholderToken = void 0;
|
|
4
|
+
const AbstractToken_1 = require("../AbstractToken");
|
|
5
|
+
/**
|
|
6
|
+
* A format-string delimiter pair containing one expression.
|
|
7
|
+
*/
|
|
8
|
+
class PlaceholderToken extends AbstractToken_1.AbstractToken {
|
|
9
|
+
constructor(expression, start = 0) {
|
|
10
|
+
super(start);
|
|
11
|
+
this.expression = expression;
|
|
12
|
+
Object.freeze(this);
|
|
13
|
+
}
|
|
14
|
+
get children() {
|
|
15
|
+
return this.expression.tokens;
|
|
16
|
+
}
|
|
17
|
+
raw() {
|
|
18
|
+
return `{${this.expression.raw()}}`;
|
|
19
|
+
}
|
|
20
|
+
clone() {
|
|
21
|
+
return new PlaceholderToken(this.expression.clone(), this.start);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.PlaceholderToken = PlaceholderToken;
|
|
25
|
+
//# sourceMappingURL=PlaceholderToken.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlaceholderToken.js","sourceRoot":"","sources":["../../../src/tokens/text/PlaceholderToken.ts"],"names":[],"mappings":";;;AAAA,oDAAiD;AAGjD;;GAEG;AACH,sBAAiF,SAAQ,6BAAa;IACpG,YACW,UAAa,EACtB,KAAK,GAAG,CAAC;QAET,KAAK,CAAC,KAAK,CAAC,CAAC;0BAHJ,UAAU;QAInB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;IAChC,CAAC;IAED,GAAG;QACD,OAAO,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC;IACtC,CAAC;IAED,KAAK;QACH,OAAO,IAAI,gBAAgB,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;IACnE,CAAC;CACF","sourcesContent":["import { AbstractToken } from '../AbstractToken';\nimport type { AbstractExpression } from '../../expressions/AbstractExpression';\n\n/**\n * A format-string delimiter pair containing one expression.\n */\nexport class PlaceholderToken<T extends AbstractExpression = AbstractExpression> extends AbstractToken {\n constructor(\n readonly expression: T,\n start = 0\n ) {\n super(start);\n Object.freeze(this);\n }\n\n get children(): readonly AbstractToken[] {\n return this.expression.tokens;\n }\n\n raw(): string {\n return `{${this.expression.raw()}}`;\n }\n\n clone(): PlaceholderToken<T> {\n return new PlaceholderToken(this.expression.clone(), this.start);\n }\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TextToken = void 0;
|
|
4
|
+
const AbstractToken_1 = require("../AbstractToken");
|
|
5
|
+
/**
|
|
6
|
+
* Original text, including any escaped format-string braces.
|
|
7
|
+
*/
|
|
8
|
+
class TextToken extends AbstractToken_1.AbstractToken {
|
|
9
|
+
static fromValue(value, start = 0) {
|
|
10
|
+
return new TextToken(value.replace(/{/g, '{{').replace(/}/g, '}}'), start);
|
|
11
|
+
}
|
|
12
|
+
constructor(source, start = 0) {
|
|
13
|
+
super(start);
|
|
14
|
+
this.source = source;
|
|
15
|
+
Object.freeze(this);
|
|
16
|
+
}
|
|
17
|
+
raw() {
|
|
18
|
+
return this.source;
|
|
19
|
+
}
|
|
20
|
+
clone() {
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
get decodedText() {
|
|
24
|
+
return this.source.replace(/{{/g, '{').replace(/}}/g, '}');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.TextToken = TextToken;
|
|
28
|
+
//# sourceMappingURL=TextToken.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextToken.js","sourceRoot":"","sources":["../../../src/tokens/text/TextToken.ts"],"names":[],"mappings":";;;AAAA,oDAAiD;AAEjD;;GAEG;AACH,eAAuB,SAAQ,6BAAa;IAC1C,MAAM,CAAC,SAAS,CAAC,KAAa,EAAE,KAAK,GAAG,CAAC;QACvC,OAAO,IAAI,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC;IAC7E,CAAC;IAED,YACW,MAAc,EACvB,KAAK,GAAG,CAAC;QAET,KAAK,CAAC,KAAK,CAAC,CAAC;sBAHJ,MAAM;QAIf,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;IAED,GAAG;QACD,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,KAAK;QACH,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC7D,CAAC;CACF","sourcesContent":["import { AbstractToken } from '../AbstractToken';\n\n/**\n * Original text, including any escaped format-string braces.\n */\nexport class TextToken extends AbstractToken {\n static fromValue(value: string, start = 0): TextToken {\n return new TextToken(value.replace(/{/g, '{{').replace(/}/g, '}}'), start);\n }\n\n constructor(\n readonly source: string,\n start = 0\n ) {\n super(start);\n Object.freeze(this);\n }\n\n raw(): string {\n return this.source;\n }\n\n clone(): this {\n return this;\n }\n\n get decodedText(): string {\n return this.source.replace(/{{/g, '{').replace(/}}/g, '}');\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":"7.0.2","root":[[89,90],[93,94],[96,99],[111,128]],"packageJsons":["../../../node_modules/.pnpm/@babel+parser@8.0.7/node_modules/@babel/parser/package.json","../../../node_modules/.pnpm/@babel+traverse@8.0.7/node_modules/@babel/traverse/package.json","../../../node_modules/.pnpm/@babel+types@8.0.6/node_modules/@babel/types/package.json","../package.json","../../type-system/package.json"],"missingPackageJsons":["../../../node_modules/.pnpm/@babel+parser@8.0.7/node_modules/@babel/parser/lib/package.json","../../../node_modules/.pnpm/@babel+parser@8.0.7/node_modules/@babel/parser/node_modules/@babel/types/package.json","../../../node_modules/.pnpm/@babel+traverse@8.0.7/node_modules/@babel/traverse/lib/package.json","../../../node_modules/.pnpm/@babel+traverse@8.0.7/node_modules/@babel/traverse/node_modules/@babel/types/package.json","../../../node_modules/.pnpm/@babel+types@8.0.6/node_modules/@babel/types/lib/package.json"],"fileNames":["lib.es5.d.ts","lib.es2015.d.ts","lib.es2016.d.ts","lib.es2017.d.ts","lib.es2018.d.ts","lib.es2019.d.ts","lib.es2020.d.ts","lib.es2021.d.ts","lib.es2022.d.ts","lib.es2023.d.ts","lib.es2024.d.ts","lib.es2025.d.ts","lib.esnext.d.ts","lib.dom.d.ts","lib.es2015.core.d.ts","lib.es2015.collection.d.ts","lib.es2015.generator.d.ts","lib.es2015.iterable.d.ts","lib.es2015.promise.d.ts","lib.es2015.proxy.d.ts","lib.es2015.reflect.d.ts","lib.es2015.symbol.d.ts","lib.es2015.symbol.wellknown.d.ts","lib.es2016.array.include.d.ts","lib.es2016.intl.d.ts","lib.es2017.arraybuffer.d.ts","lib.es2017.date.d.ts","lib.es2017.object.d.ts","lib.es2017.sharedmemory.d.ts","lib.es2017.string.d.ts","lib.es2017.intl.d.ts","lib.es2017.typedarrays.d.ts","lib.es2018.asyncgenerator.d.ts","lib.es2018.asynciterable.d.ts","lib.es2018.intl.d.ts","lib.es2018.promise.d.ts","lib.es2018.regexp.d.ts","lib.es2019.array.d.ts","lib.es2019.object.d.ts","lib.es2019.string.d.ts","lib.es2019.symbol.d.ts","lib.es2019.intl.d.ts","lib.es2020.bigint.d.ts","lib.es2020.date.d.ts","lib.es2020.promise.d.ts","lib.es2020.sharedmemory.d.ts","lib.es2020.string.d.ts","lib.es2020.symbol.wellknown.d.ts","lib.es2020.intl.d.ts","lib.es2020.number.d.ts","lib.es2021.promise.d.ts","lib.es2021.string.d.ts","lib.es2021.weakref.d.ts","lib.es2021.intl.d.ts","lib.es2022.array.d.ts","lib.es2022.error.d.ts","lib.es2022.intl.d.ts","lib.es2022.object.d.ts","lib.es2022.string.d.ts","lib.es2022.regexp.d.ts","lib.es2023.array.d.ts","lib.es2023.collection.d.ts","lib.es2023.intl.d.ts","lib.es2024.arraybuffer.d.ts","lib.es2024.collection.d.ts","lib.es2024.object.d.ts","lib.es2024.promise.d.ts","lib.es2024.regexp.d.ts","lib.es2024.sharedmemory.d.ts","lib.es2024.string.d.ts","lib.es2025.collection.d.ts","lib.es2025.float16.d.ts","lib.es2025.intl.d.ts","lib.es2025.iterator.d.ts","lib.es2025.promise.d.ts","lib.es2025.regexp.d.ts","lib.esnext.array.d.ts","lib.esnext.collection.d.ts","lib.esnext.date.d.ts","lib.esnext.decorators.d.ts","lib.esnext.disposable.d.ts","lib.esnext.error.d.ts","lib.esnext.intl.d.ts","lib.esnext.sharedmemory.d.ts","lib.esnext.temporal.d.ts","lib.esnext.typedarrays.d.ts","lib.decorators.d.ts","lib.decorators.legacy.d.ts","../src/tokens/AbstractToken.ts","../src/tokens/text/TextToken.ts","../../../node_modules/.pnpm/@babel+types@8.0.6/node_modules/@babel/types/lib/index.d.ts","../../../node_modules/.pnpm/@babel+traverse@8.0.7/node_modules/@babel/traverse/lib/index.d.ts","../src/tokens/code/CodeToken.ts","../src/code-parsers/CodeParser.ts","../../../node_modules/.pnpm/@babel+parser@8.0.7/node_modules/@babel/parser/lib/index.d.ts","../src/code-parsers/JavaScriptParser.ts","../src/tokens/code/JSToken.ts","../src/tokens/code/IdentifierToken.ts","../src/tokens/code/PrefixToken.ts","../../type-system/dist/@types/Formatter.d.ts","../../type-system/dist/@types/Type.d.ts","../../type-system/dist/@types/ObjectType.d.ts","../../type-system/dist/@types/ArrayType.d.ts","../../type-system/dist/@types/UnknownType.d.ts","../../type-system/dist/@types/ScalarType.d.ts","../../type-system/dist/@types/TextType.d.ts","../../type-system/dist/@types/NumberType.d.ts","../../type-system/dist/@types/IntegerType.d.ts","../../type-system/dist/@types/BooleanType.d.ts","../../type-system/dist/@types/index.d.ts","../src/definitions/ValidationContext.ts","../src/expressions/AbstractExpression.ts","../src/tokens/text/PlaceholderToken.ts","../src/utils/tokenUtils.ts","../src/tokens/index.ts","../src/ExpressionParser.ts","../src/CombinedParser.ts","../src/expressions/EvaluatedExpression.ts","../src/expressions/shorthand/ShorthandExpression.ts","../src/expressions/shorthand/FormatShorthandExpression.ts","../src/expressions/constant/ConstantExpression.ts","../src/expressions/function/FunctionExpression.ts","../src/expressions/text/AbstractFormatExpression.ts","../src/expressions/text/FormatStringExpression.ts","../src/expressions/index.ts","../src/utils/parserUtils.ts","../src/utils/valueFormatting.ts","../src/index.ts"],"fileInfos":[{"version":"16934abaab7026ac114da441aabea1a0","affectsGlobalScope":true,"impliedNodeFormat":1},"d4306fb2e47f74835e8674ffac07d76f","e437c5c1302869326c3bb93da85bbbcf","e4324975a566567b21d350615f1fc6ac","333b1b9a2a9ac3b8497dba5c63b5ba50","6cffacd662b6eb5fa7a36aa2ea366bfa","b4c34f9c23304dbef2d23698637ed638","e5cb86a5fc491796ecd1d2dd348d208f","feb6c6fb19cdb246a5d8acb36a6901c7","9443a7f109277ffaa79d893ed2549995","793cee405385076e27c24f409659dccd","09f69c6610266eaee1ac9e3e30df2c71","62bad718844246b8e17547f37bad6085",{"version":"aae8996e8b5684814785a42cbbefcd79","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"926204c28cd3d073865348473ae28d2e","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"f25e42c801b2cb3cf2b39792006a9beb","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"6344b55f26a4e81d9608777dbfb877dd","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"3c0ed28e53d3695b363e256ec1c023fd","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"4c2761daba7f17141c25baa0821ac5da","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"b87656acabd63e69379ff6ffcfe52fc7","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"597469522da047a5af5222cc6989f405","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"1708ea4d34dc37fadadc63ca01127e80","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"55d97a8c6fbf34a30450a7b1e5f7a298","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"0ee05eb59426d33e374226d8dcfa708b","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"e347c14030993906efcfbb88915b6a05","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"b0231263857c9b6a03641acdc9280ceb","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"3b15c4a83b598cacb4067676e6f0abed","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"b417d97b7934cef63b1889abec0bbfbf","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"09a6cf4032ebba60ce22a501e663f881","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"2b056277dd138e8f5650fc04e20eaa8d","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"e22cc07e3f3cc242ba52fa3f8ea1fc58","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"2c45da767a1bfbb220848df1bc4029e4","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"b44c3e0fbaf2130cdcf6ac38b120ffa1","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"b612fb5cf8e5d964b92063a75207632a","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"02705151a5e1551b9162a9ed8ab763f7","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"41025e398be9215d32e4337335da8f0b","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"52684c2b1f353a5538e4f275182a54cd","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"6dedb6a4f90d1df3a6fbe5693e44886c","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"ca3f36fe3562c07e0f0d71c2bebd3f6d","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"409974d6129befbb8226ddd1c6558568","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"4d9cfde2a1ae1b4925f1f9bc10848e5d","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"7e1daecc66dd564144e3bb1a0266b5fd","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"a8e1d9bb35fd0637f2f9fd2b2a54f2ec","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"4f168501772a6543182765bfd5f2fbfe","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"a19c80aad1b2162103496f5ba293a732","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"b69afa63cd5d059851c78adb2856ee09","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"ae2fc5d954e9b0f5feee3d481b953c27","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"1cfd3091a071d8b6feec15277643bafe","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"1da2c1f258970fd3cc91184f69e91a9d","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"a0d87491913d843139e0c993650a3235","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"4ef72aa378127e7b7abba915b0110b1e","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"3ec74c6a7d4463f0254db3a74cf75646","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"84c2bdfa470d075526cce6322d81b0b6","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"0b3844c2b8c73e4e1ab91431411cad11","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"4fc71cf4a15b8d99675a31df77f26e07","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"d1b49564ddaeca3df5b6dbae925d2242","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"6a25be566d60ccfc2d6e8b7bfdeefa83","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"8a20e27646985dfd58c57ca6566553dd","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"9969f02ad3cdcbf4f709405cda44167f","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"9c9be4792a7a4f42c15ae7360bf28779","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"8cf777fe00349b71ee9c4b6f3fe7fd19","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"74f96bc192530c9723f572bfff3d3078","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"1df91c56b25955c56387426f378173c5","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"38856f70edcd2115c355d96ec77cc09e","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"de8700156c1275465bcd473c28b359aa","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"d47cfdb6ede40518357bb5a4cd7cd9fb","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"6e5773860cd9e5b15e683113f642ab47","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"30ff5fe1682f7fcd629880476ca3c2e0","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"bf23d7d1b40b9015b694ddc2f011752f","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"2cc585d42e2c548f9f24a30a1989fd33","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"713906ce9d332d2242b7f05ed9304be3","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"0219894bfe5042c7e1aa2d22e4a91ed0","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"6009ffff7e43c93318804d2d28e37fe3","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"03be89b227587594fbb50509fc1c2e45","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"b30df52dc24740c0bad7c55c3511df7d","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"ab8d3c9b5ed5c2ab8f383607eef439f0","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"d950ec671d0a8e07f3c1a31e94abed86","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"1abef2ace5eccb02d60dd73cd5a5ee4c","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"f5f0a3044029d1cc081b5887eb4deb07","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"d57c697f1446940ec4bfe669c962e2c4","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"be41035d7b941482a1e1ae6a5c5dcca5","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"10f7d9da7564f27f8ddf4a162b6da6d3","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"1d0520af549e0c3581f15173cc713ca1","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"d65083f97fd741cff028472563eddb79","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"da7f24f00653ebac660ac1c0821ed33d","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"7cb5ae9e65516ea2235f0721f6aac43c","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"f64453cbf9671f28158677fa5c43967a","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"33f317af5428801f944a478d2c1e38e5","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"1f9398f3eec050714be4f9b1c3a2317d","signature":"510b0b622fafd6eff2bf5d020de046ee","impliedNodeFormat":1},{"version":"36194741ebb41739843db9a2ee86ca6f","signature":"f25290e9ca5aee09a0210e2a454437f8","impliedNodeFormat":1},{"version":"3575b2b8e50b5a5b3acce219e08900c5","impliedNodeFormat":99},{"version":"ba148a7a8b1b345b82e2255648d7a2a0","impliedNodeFormat":99},{"version":"79de825e280a92f200bf8ab73df74aaa","signature":"968dbf07ccc13a1a84f319c26e9909b3","impliedNodeFormat":1},{"version":"cbe2ad0843a3b4397021171b675d91e2","signature":"e78cf9dc5bca6011a220581f56da19cb","impliedNodeFormat":1},{"version":"436d7d9cea8d7f3e41e2ea50138ad4da","impliedNodeFormat":99},{"version":"6341abc9e164a58cd4faf7db00c2125e","signature":"25aba7d58ecafcf7098f9bcca63ea72a","impliedNodeFormat":1},{"version":"1f637dbc1f68ca19c0568ac3979a5a59","signature":"354fc88481ff608fcbbfaf7851a29043","impliedNodeFormat":1},{"version":"8c8e53d56beef78deb845941070bc387","signature":"3058c9c4ad1200a2ff62094072deed53","impliedNodeFormat":1},{"version":"72d344412c308ce31e59dd6752f5abca","signature":"bf6d579deb9596ec514083ea94789be0","impliedNodeFormat":1},"e5fb7990b84f5089ba92554ea3614810","770ee32ef332fd48bfef508442b30edb","5c1b5931ee0c894699ca56f5b573f88a","822b842ad7efa3485d65fbeb2f919865","89b6053090a8d01f57cb8f521fae777d","26302a8b72d74f944dcf8f6452e54f7c","bc95bdb594a5aece18248fbf4387dd2e","90125a76f2ae701181f7e09dea41f3ad","ac52bb76ccad935a013384d2a71ab267","2c96eeb69afb823580d4e1e5f1b188e0","c06213bcb24cd658dfcd1239777159bd",{"version":"787551f4ccf1ea187c97a6fef4a2b502","signature":"ada7f0921b6eace272ee48028595ff4e","impliedNodeFormat":1},{"version":"67323509d98791c2e9287e7b9c86c8f1","signature":"e518fcc525a72f156f4235f97e942e72","impliedNodeFormat":1},{"version":"2f588b7565009cf660e49f19128363d2","signature":"cf3121ca4479d3afdaceb690d14cf086","impliedNodeFormat":1},{"version":"4b2dcd692e0308ac4cee04202b63a5c0","signature":"d33a7d16b8bb10392237228466f959f8","impliedNodeFormat":1},"6af0ffa3e62b22f41a12a99343633ffd",{"version":"01cb6d1d819779d9823af5890a75765a","signature":"c0cbc64b7a419382086b8d30226b8f0f","impliedNodeFormat":1},{"version":"2e3387bb780ecbc47d2cf0715f0a3d5b","signature":"bb9d86257bed6b06d027b9b561ba2c31","impliedNodeFormat":1},{"version":"ca57df7a021dd9e60b50a86359328369","signature":"e62a96adf38e2e5adbeb996a1bbb0ca6","impliedNodeFormat":1},{"version":"89c28146623ca911251a5a7c0aef31da","signature":"358284d17020fff7c8988fe49465ebce","impliedNodeFormat":1},{"version":"8585c59b42a4515d919ae67b1871b611","signature":"788ca99c9132de5f347c0c196085cc16","impliedNodeFormat":1},{"version":"f9b746229b5805be47a5e729cd0882b9","signature":"74a85c95eb3b8b1bd5c7d0822fe65312","impliedNodeFormat":1},{"version":"42149341c32f9a8c00c6c6b7f916c138","signature":"f85883c070822e429d13802a651146bc","impliedNodeFormat":1},{"version":"e5172b410a188df0e6366797579dc23a","signature":"038c82b1bfec7b11761d58241d68970f","impliedNodeFormat":1},{"version":"43287bfa29ccc772782a499966bf000e","signature":"fa4b9cdace3ba0abd1e6547b87390de6","impliedNodeFormat":1},{"version":"6af68c46f3329122591b4b2209008456","signature":"f616c8f4ac91b2029f1e1d5cc2d36adf","impliedNodeFormat":1},{"version":"ee144db1b2a390284f2301277a4769d0","signature":"6844f7dcecd5297f9a25fe55fe7aeacc","impliedNodeFormat":1},{"version":"e8e9d0b6b6e01ab0a9a3b771fca4b37b","signature":"90506d77482148f93c56044616613958","impliedNodeFormat":1},{"version":"b0ffa465ccd4d217e0b238fd935d8127","signature":"3a5ea1baf065ad0e1794aeb15153114c","impliedNodeFormat":1}],"fileIdsList":[[91],[112,115,116],[112,115],[91,92,94,95],[110,115],[111,115],[110,112,115,116],[112,115,116,118],[112,118,119,120,121,122,123,124],[115,116,119],[110,111,112,115,116],[111,112,115,116],[115,117,118,119,120,122,123],[94,96,111,115,116,117,125,126,127],[89],[89,90,91,92,93,94,96],[89,98],[89,90,93,97,98,99,113,114],[89,112],[115,117,125],[89,93,97,99],[110],[101],[101,105],[100],[100,101,102,103,104,105,106,107,108,109]],"options":{"composite":true,"declaration":true,"declarationDir":"./@types","inlineSources":true,"module":199,"outDir":"./","rootDir":"../src","skipLibCheck":true,"strict":false,"stripInternal":true,"sourceMap":true,"target":4,"tsBuildInfoFile":"./tsconfig.tsbuildinfo","esModuleInterop":true},"referencedMap":[[95,1],[92,1],[117,2],[116,3],[96,4],[111,5],[112,6],[118,2],[121,7],[122,8],[125,9],[120,10],[119,11],[123,12],[124,13],[128,14],[93,15],[98,15],[97,16],[99,17],[115,18],[113,19],[90,15],[126,20],[114,21],[127,22],[103,23],[109,24],[108,24],[107,24],[102,23],[105,23],[106,24],[101,25],[104,23],[110,26]],"latestChangedDtsFile":"./@types/index.d.ts"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseExpression = parseExpression;
|
|
4
|
+
const CombinedParser_1 = require("../CombinedParser");
|
|
5
|
+
const expressions_1 = require("../expressions");
|
|
6
|
+
/**
|
|
7
|
+
* Recognize evaluated code and references before preserving remaining input as constant text.
|
|
8
|
+
* Callers can compose their own parser order instead.
|
|
9
|
+
*/
|
|
10
|
+
function parseExpression(source, start = 0) {
|
|
11
|
+
return new CombinedParser_1.CombinedParser([
|
|
12
|
+
new expressions_1.FunctionExpressionParser(),
|
|
13
|
+
new expressions_1.EvaluatedExpressionParser(),
|
|
14
|
+
new expressions_1.FormatShorthandExpressionParser(),
|
|
15
|
+
new expressions_1.ShorthandExpressionParser(),
|
|
16
|
+
new expressions_1.ConstantExpressionParser()
|
|
17
|
+
]).tryParse(source, start);
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=parserUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parserUtils.js","sourceRoot":"","sources":["../../src/utils/parserUtils.ts"],"names":[],"mappings":";;;AAAA,sDAAmD;AACnD,gDAOwB;AAGxB;;;GAGG;AACH,yBAAgC,MAAwB,EAAE,KAAK,GAAG,CAAC;IACjE,OAAO,IAAI,+BAAc,CAAqB;QAC5C,IAAI,sCAAwB,EAAE;QAC9B,IAAI,uCAAyB,EAAE;QAC/B,IAAI,6CAA+B,EAAE;QACrC,IAAI,uCAAyB,EAAE;QAC/B,IAAI,sCAAwB,EAAE;KAC/B,CAAC,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["import { CombinedParser } from '../CombinedParser';\nimport {\n AbstractExpression,\n EvaluatedExpressionParser,\n ConstantExpressionParser,\n FormatShorthandExpressionParser,\n FunctionExpressionParser,\n ShorthandExpressionParser\n} from '../expressions';\nimport { ExpressionSource } from '../tokens';\n\n/**\n * Recognize evaluated code and references before preserving remaining input as constant text.\n * Callers can compose their own parser order instead.\n */\nexport function parseExpression(source: ExpressionSource, start = 0): AbstractExpression | null {\n return new CombinedParser<AbstractExpression>([\n new FunctionExpressionParser(),\n new EvaluatedExpressionParser(),\n new FormatShorthandExpressionParser(),\n new ShorthandExpressionParser(),\n new ConstantExpressionParser()\n ]).tryParse(source, start);\n}\n"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stringify = stringify;
|
|
4
|
+
exports.codeToken = codeToken;
|
|
5
|
+
exports.javascriptToken = javascriptToken;
|
|
6
|
+
exports.hasFunctionPrefix = hasFunctionPrefix;
|
|
7
|
+
exports.leadingTrivia = leadingTrivia;
|
|
8
|
+
const CodeToken_1 = require("../tokens/code/CodeToken");
|
|
9
|
+
const JSToken_1 = require("../tokens/code/JSToken");
|
|
10
|
+
const PrefixToken_1 = require("../tokens/code/PrefixToken");
|
|
11
|
+
function stringify(source) {
|
|
12
|
+
let text;
|
|
13
|
+
if (typeof source === 'string') {
|
|
14
|
+
text = source;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
text = source.map((token) => token.raw()).join('');
|
|
18
|
+
}
|
|
19
|
+
return text;
|
|
20
|
+
}
|
|
21
|
+
function codeToken(tokens) {
|
|
22
|
+
const code = tokens.filter((token) => token instanceof CodeToken_1.CodeToken);
|
|
23
|
+
if (code.length !== 1)
|
|
24
|
+
throw new SyntaxError('Expected one code token.');
|
|
25
|
+
return code[0];
|
|
26
|
+
}
|
|
27
|
+
function javascriptToken(tokens) {
|
|
28
|
+
const javascript = tokens.filter((token) => token instanceof JSToken_1.JSToken);
|
|
29
|
+
if (javascript.length !== 1) {
|
|
30
|
+
throw new SyntaxError('Expected one JavaScript token.');
|
|
31
|
+
}
|
|
32
|
+
return javascript[0];
|
|
33
|
+
}
|
|
34
|
+
function hasFunctionPrefix(source) {
|
|
35
|
+
return source.slice(leadingTrivia(source).length).startsWith(PrefixToken_1.FUNCTION_PREFIX);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Whitespace and comments before a Journey prefix remain original source text.
|
|
39
|
+
*/
|
|
40
|
+
function leadingTrivia(source) {
|
|
41
|
+
return source.match(/^(?:\s+|\/\*[\s\S]*?\*\/|\/\/[^\r\n]*(?:\r?\n|$))*/)[0];
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=tokenUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenUtils.js","sourceRoot":"","sources":["../../src/utils/tokenUtils.ts"],"names":[],"mappings":";;;;;;;AACA,wDAAqD;AACrD,oDAAiD;AACjD,4DAA6D;AAE7D,mBAA0B,MAAwB;IAChD,IAAI,IAAY,CAAC;IACjB,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,IAAI,GAAG,MAAM,CAAC;IAChB,CAAC;SAAM,CAAC;QACN,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACrD,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,mBAA0B,MAAgC;IACxD,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAsB,EAAE,CAAC,KAAK,YAAY,qBAAS,CAAC,CAAC;IACtF,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,WAAW,CAAC,0BAA0B,CAAC,CAAC;IACzE,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC;AACjB,CAAC;AAED,yBAAgC,MAAgC;IAC9D,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAoB,EAAE,CAAC,KAAK,YAAY,iBAAO,CAAC,CAAC;IACxF,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,WAAW,CAAC,gCAAgC,CAAC,CAAC;IAC1D,CAAC;IACD,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC;AACvB,CAAC;AAED,2BAAkC,MAAc;IAC9C,OAAO,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,UAAU,CAAC,6BAAe,CAAC,CAAC;AAChF,CAAC;AAED;;GAEG;AACH,uBAA8B,MAAc;IAC1C,OAAO,MAAM,CAAC,KAAK,CAAC,oDAAoD,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/E,CAAC","sourcesContent":["import { AbstractToken, ExpressionSource } from '../tokens/AbstractToken';\nimport { CodeToken } from '../tokens/code/CodeToken';\nimport { JSToken } from '../tokens/code/JSToken';\nimport { FUNCTION_PREFIX } from '../tokens/code/PrefixToken';\n\nexport function stringify(source: ExpressionSource): string {\n let text: string;\n if (typeof source === 'string') {\n text = source;\n } else {\n text = source.map((token) => token.raw()).join('');\n }\n return text;\n}\n\nexport function codeToken(tokens: readonly AbstractToken[]): CodeToken {\n const code = tokens.filter((token): token is CodeToken => token instanceof CodeToken);\n if (code.length !== 1) throw new SyntaxError('Expected one code token.');\n return code[0];\n}\n\nexport function javascriptToken(tokens: readonly AbstractToken[]): JSToken {\n const javascript = tokens.filter((token): token is JSToken => token instanceof JSToken);\n if (javascript.length !== 1) {\n throw new SyntaxError('Expected one JavaScript token.');\n }\n return javascript[0];\n}\n\nexport function hasFunctionPrefix(source: string): boolean {\n return source.slice(leadingTrivia(source).length).startsWith(FUNCTION_PREFIX);\n}\n\n/**\n * Whitespace and comments before a Journey prefix remain original source text.\n */\nexport function leadingTrivia(source: string): string {\n return source.match(/^(?:\\s+|\\/\\*[\\s\\S]*?\\*\\/|\\/\\/[^\\r\\n]*(?:\\r?\\n|$))*/)[0];\n}\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatValue = formatValue;
|
|
4
|
+
exports.formatValueAsync = formatValueAsync;
|
|
5
|
+
/**
|
|
6
|
+
* Format an expression with a specific format.
|
|
7
|
+
*/
|
|
8
|
+
function formatValue(value, formatter, format) {
|
|
9
|
+
if (value == null) {
|
|
10
|
+
return '';
|
|
11
|
+
}
|
|
12
|
+
else if ((formatter === null || formatter === void 0 ? void 0 : formatter.format) != null) {
|
|
13
|
+
return formatter.format(value, format !== null && format !== void 0 ? format : undefined);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
// This should generally not happen. However, we still try to handle it gracefully.
|
|
17
|
+
// This is useful for tests where we don't want to define the type for every variable.
|
|
18
|
+
return value.toString();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Resolve an object's asynchronous display value before falling back to its type formatter.
|
|
23
|
+
*/
|
|
24
|
+
async function formatValueAsync(value, formatter, format) {
|
|
25
|
+
let formatted;
|
|
26
|
+
if (value != null && typeof value._display === 'function') {
|
|
27
|
+
formatted = await value._display();
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
formatted = formatValue(value, formatter, format);
|
|
31
|
+
}
|
|
32
|
+
return formatted;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=valueFormatting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"valueFormatting.js","sourceRoot":"","sources":["../../src/utils/valueFormatting.ts"],"names":[],"mappings":";;;;AAEA;;GAEG;AACH,qBAA4B,KAAU,EAAE,SAA2B,EAAE,MAAsB;IACzF,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;QAClB,OAAO,EAAE,CAAC;IACZ,CAAC;SAAM,IAAI,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,MAAM,KAAI,IAAI,EAAE,CAAC;QACrC,OAAO,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,SAAS,CAAC,CAAC;IACtD,CAAC;SAAM,CAAC;QACN,mFAAmF;QACnF,sFAAsF;QACtF,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;IAC1B,CAAC;AACH,CAAC;AAED;;GAEG;AACI,KAAK,2BACV,KAAU,EACV,SAA2B,EAC3B,MAAsB;IAEtB,IAAI,SAAiB,CAAC;IACtB,IAAI,KAAK,IAAI,IAAI,IAAI,OAAO,KAAK,CAAC,QAAQ,KAAK,UAAU,EAAE,CAAC;QAC1D,SAAS,GAAG,MAAM,KAAK,CAAC,QAAQ,EAAE,CAAC;IACrC,CAAC;SAAM,CAAC;QACN,SAAS,GAAG,WAAW,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IACpD,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import type { Formatter } from '@ja-platform/parser-type-system';\n\n/**\n * Format an expression with a specific format.\n */\nexport function formatValue(value: any, formatter: Formatter | null, format?: string | null): string {\n if (value == null) {\n return '';\n } else if (formatter?.format != null) {\n return formatter.format(value, format ?? undefined);\n } else {\n // This should generally not happen. However, we still try to handle it gracefully.\n // This is useful for tests where we don't want to define the type for every variable.\n return value.toString();\n }\n}\n\n/**\n * Resolve an object's asynchronous display value before falling back to its type formatter.\n */\nexport async function formatValueAsync(\n value: any,\n formatter: Formatter | null,\n format?: string | null\n): Promise<string> {\n let formatted: string;\n if (value != null && typeof value._display === 'function') {\n formatted = await value._display();\n } else {\n formatted = formatValue(value, formatter, format);\n }\n return formatted;\n}\n"]}
|