@rangular-framework/cli 0.0.0-stage → 1.0.0
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/cli/src/cli.js +1217 -0
- package/dist/compiler/src/catalog.js +198 -0
- package/dist/compiler/src/class/formInit.js +370 -0
- package/dist/compiler/src/class/parseComponent.js +430 -0
- package/dist/compiler/src/class/parseDirective.js +227 -0
- package/dist/compiler/src/class/parseRoutes.js +163 -0
- package/dist/compiler/src/codegen/generate.js +3466 -0
- package/dist/compiler/src/codegen/methods.js +975 -0
- package/dist/compiler/src/codegen/sourceMap.js +77 -0
- package/dist/compiler/src/compile.js +775 -0
- package/dist/compiler/src/diagnostics.js +113 -0
- package/dist/compiler/src/doctor.js +144 -0
- package/dist/compiler/src/fix.js +44 -0
- package/dist/compiler/src/index.js +38 -0
- package/dist/compiler/src/preview/renderPreview.js +7158 -0
- package/dist/compiler/src/preview/styleSnapshot.js +268 -0
- package/dist/compiler/src/propTable.js +107 -0
- package/dist/compiler/src/style/css.js +161 -0
- package/dist/compiler/src/template/ast.js +19 -0
- package/dist/compiler/src/template/evaluate.js +151 -0
- package/dist/compiler/src/template/expr.js +360 -0
- package/dist/compiler/src/template/forms.js +80 -0
- package/dist/compiler/src/template/literal.js +248 -0
- package/dist/compiler/src/template/parser.js +230 -0
- package/dist/compiler/src/template/pipes.js +225 -0
- package/dist/compiler/src/template/printAst.js +38 -0
- package/dist/compiler/src/template/structural.js +51 -0
- package/dist/runtime/src/index.js +1197 -0
- package/dist/ui/src/chart.js +196 -0
- package/dist/ui/src/datetime.js +240 -0
- package/dist/ui/src/icons.js +310 -0
- package/dist/ui/src/mask.js +103 -0
- package/dist/ui/src/palette.js +141 -0
- package/dist/ui/src/tokens.js +173 -0
- package/package.json +28 -4
- package/README.md +0 -3
|
@@ -0,0 +1,248 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.literalValue = literalValue;
|
|
37
|
+
exports.isLiteralSource = isLiteralSource;
|
|
38
|
+
exports.initializerUsesThis = initializerUsesThis;
|
|
39
|
+
exports.evaluateExprInitializer = evaluateExprInitializer;
|
|
40
|
+
const ts = __importStar(require("typescript"));
|
|
41
|
+
/**
|
|
42
|
+
* Evaluate a field initializer that is composed purely of literals:
|
|
43
|
+
* strings, numbers, booleans, null, arrays and objects (nested), with
|
|
44
|
+
* unary minus on numbers. Anything else (identifiers, calls, spreads,
|
|
45
|
+
* methods, template substitutions) is NOT a literal and reports
|
|
46
|
+
* { ok: false }, callers keep their warning + TODO behaviour for those.
|
|
47
|
+
*
|
|
48
|
+
* Implemented by walking the TypeScript AST, never by eval/Function.
|
|
49
|
+
*/
|
|
50
|
+
function literalValue(initializer) {
|
|
51
|
+
const sf = ts.createSourceFile('literal.ts', `const __v = ${initializer};`, ts.ScriptTarget.Latest,
|
|
52
|
+
/* setParentNodes */ false);
|
|
53
|
+
let expr;
|
|
54
|
+
const visit = (node) => {
|
|
55
|
+
if (expr)
|
|
56
|
+
return;
|
|
57
|
+
if (ts.isVariableDeclaration(node) && node.initializer)
|
|
58
|
+
expr = node.initializer;
|
|
59
|
+
else
|
|
60
|
+
ts.forEachChild(node, visit);
|
|
61
|
+
};
|
|
62
|
+
visit(sf);
|
|
63
|
+
if (!expr)
|
|
64
|
+
return { ok: false };
|
|
65
|
+
return walk(expr);
|
|
66
|
+
}
|
|
67
|
+
function walk(node) {
|
|
68
|
+
if (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) {
|
|
69
|
+
return { ok: true, value: node.text };
|
|
70
|
+
}
|
|
71
|
+
if (ts.isNumericLiteral(node))
|
|
72
|
+
return { ok: true, value: Number(node.text) };
|
|
73
|
+
if (node.kind === ts.SyntaxKind.TrueKeyword)
|
|
74
|
+
return { ok: true, value: true };
|
|
75
|
+
if (node.kind === ts.SyntaxKind.FalseKeyword)
|
|
76
|
+
return { ok: true, value: false };
|
|
77
|
+
if (node.kind === ts.SyntaxKind.NullKeyword)
|
|
78
|
+
return { ok: true, value: null };
|
|
79
|
+
if (ts.isPrefixUnaryExpression(node) && node.operator === ts.SyntaxKind.MinusToken) {
|
|
80
|
+
const inner = walk(node.operand);
|
|
81
|
+
return inner.ok && typeof inner.value === 'number'
|
|
82
|
+
? { ok: true, value: -inner.value }
|
|
83
|
+
: { ok: false };
|
|
84
|
+
}
|
|
85
|
+
if (ts.isArrayLiteralExpression(node)) {
|
|
86
|
+
const out = [];
|
|
87
|
+
for (const el of node.elements) {
|
|
88
|
+
const r = walk(el);
|
|
89
|
+
if (!r.ok)
|
|
90
|
+
return { ok: false };
|
|
91
|
+
out.push(r.value);
|
|
92
|
+
}
|
|
93
|
+
return { ok: true, value: out };
|
|
94
|
+
}
|
|
95
|
+
if (ts.isObjectLiteralExpression(node)) {
|
|
96
|
+
const out = {};
|
|
97
|
+
for (const prop of node.properties) {
|
|
98
|
+
if (ts.isPropertyAssignment(prop)) {
|
|
99
|
+
const key = keyOf(prop.name);
|
|
100
|
+
if (key === undefined)
|
|
101
|
+
return { ok: false };
|
|
102
|
+
const r = walk(prop.initializer);
|
|
103
|
+
if (!r.ok)
|
|
104
|
+
return { ok: false };
|
|
105
|
+
// defineProperty, not assignment: a key like "__proto__" must
|
|
106
|
+
// become an own data property (the JSON.parse semantics), never
|
|
107
|
+
// a prototype mutation of the object being built.
|
|
108
|
+
Object.defineProperty(out, key, {
|
|
109
|
+
value: r.value, enumerable: true, writable: true, configurable: true,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
else if (ts.isShorthandPropertyAssignment(prop)) {
|
|
113
|
+
// `({ x })` refers to a variable, not a literal.
|
|
114
|
+
return { ok: false };
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
return { ok: false };
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return { ok: true, value: out };
|
|
121
|
+
}
|
|
122
|
+
if (ts.isParenthesizedExpression(node))
|
|
123
|
+
return walk(node.expression);
|
|
124
|
+
return { ok: false };
|
|
125
|
+
}
|
|
126
|
+
function keyOf(name) {
|
|
127
|
+
if (ts.isIdentifier(name) || ts.isStringLiteral(name) || ts.isNumericLiteral(name)) {
|
|
128
|
+
return name.text;
|
|
129
|
+
}
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
/** True when the initializer source is a literal (or nested literal structure). */
|
|
133
|
+
function isLiteralSource(initializer) {
|
|
134
|
+
return literalValue(initializer).ok;
|
|
135
|
+
}
|
|
136
|
+
/** Parse an initializer into its expression node (shared by the walks below). */
|
|
137
|
+
function initializerExpression(initializer) {
|
|
138
|
+
const sf = ts.createSourceFile('literal.ts', `const __v = ${initializer};`, ts.ScriptTarget.Latest,
|
|
139
|
+
/* setParentNodes */ false);
|
|
140
|
+
let expr;
|
|
141
|
+
const visit = (node) => {
|
|
142
|
+
if (expr)
|
|
143
|
+
return;
|
|
144
|
+
if (ts.isVariableDeclaration(node) && node.initializer)
|
|
145
|
+
expr = node.initializer;
|
|
146
|
+
else
|
|
147
|
+
ts.forEachChild(node, visit);
|
|
148
|
+
};
|
|
149
|
+
visit(sf);
|
|
150
|
+
return expr;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* True when an initializer mentions `this` anywhere (a real `this`
|
|
154
|
+
* keyword, found by walking the AST, so the word inside a string does
|
|
155
|
+
* not count). Such an initializer cannot be emitted verbatim into a
|
|
156
|
+
* generated function component, which has no `this` to resolve, and
|
|
157
|
+
* cannot be evaluated by the preview against an empty scope either.
|
|
158
|
+
*/
|
|
159
|
+
function initializerUsesThis(initializer) {
|
|
160
|
+
const expr = initializerExpression(initializer);
|
|
161
|
+
if (!expr)
|
|
162
|
+
return true;
|
|
163
|
+
let found = false;
|
|
164
|
+
const visit = (node) => {
|
|
165
|
+
if (found)
|
|
166
|
+
return;
|
|
167
|
+
if (node.kind === ts.SyntaxKind.ThisKeyword) {
|
|
168
|
+
found = true;
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
ts.forEachChild(node, visit);
|
|
172
|
+
};
|
|
173
|
+
visit(expr);
|
|
174
|
+
return found;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Evaluate a non-literal field initializer that needs no scope: the
|
|
178
|
+
* shapes the preview can rebuild identically to the generated app,
|
|
179
|
+
* which emits such initializers verbatim (proof fix). Supported:
|
|
180
|
+
* literals, `new Date(...)` with supported arguments, `Date.now()`,
|
|
181
|
+
* unary minus, and `+ - * / %` over supported operands. Anything else
|
|
182
|
+
* (identifiers, other constructors, other calls) reports { ok: false }
|
|
183
|
+
* and callers keep the field out of the preview state, where reads of
|
|
184
|
+
* it yield undefined, the same value the generated fallback declares.
|
|
185
|
+
* Implemented by walking the TypeScript AST, never by eval/Function.
|
|
186
|
+
*/
|
|
187
|
+
function evaluateExprInitializer(initializer) {
|
|
188
|
+
const expr = initializerExpression(initializer);
|
|
189
|
+
if (!expr)
|
|
190
|
+
return { ok: false };
|
|
191
|
+
return walkExpr(expr);
|
|
192
|
+
}
|
|
193
|
+
function walkExpr(node) {
|
|
194
|
+
const lit = literalOf(node);
|
|
195
|
+
if (lit.ok)
|
|
196
|
+
return lit;
|
|
197
|
+
if (ts.isParenthesizedExpression(node))
|
|
198
|
+
return walkExpr(node.expression);
|
|
199
|
+
if (ts.isNewExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === 'Date') {
|
|
200
|
+
const args = [];
|
|
201
|
+
for (const arg of node.arguments ?? []) {
|
|
202
|
+
const r = walkExpr(arg);
|
|
203
|
+
if (!r.ok)
|
|
204
|
+
return { ok: false };
|
|
205
|
+
args.push(r.value);
|
|
206
|
+
}
|
|
207
|
+
const Ctor = Date;
|
|
208
|
+
return { ok: true, value: new Ctor(...args) };
|
|
209
|
+
}
|
|
210
|
+
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression)
|
|
211
|
+
&& ts.isIdentifier(node.expression.expression) && node.expression.expression.text === 'Date'
|
|
212
|
+
&& node.expression.name.text === 'now' && node.arguments.length === 0) {
|
|
213
|
+
return { ok: true, value: Date.now() };
|
|
214
|
+
}
|
|
215
|
+
if (ts.isPrefixUnaryExpression(node) && node.operator === ts.SyntaxKind.MinusToken) {
|
|
216
|
+
const inner = walkExpr(node.operand);
|
|
217
|
+
return inner.ok && typeof inner.value === 'number'
|
|
218
|
+
? { ok: true, value: -inner.value }
|
|
219
|
+
: { ok: false };
|
|
220
|
+
}
|
|
221
|
+
if (ts.isBinaryExpression(node)) {
|
|
222
|
+
const op = node.operatorToken.kind;
|
|
223
|
+
if (op === ts.SyntaxKind.PlusToken || op === ts.SyntaxKind.MinusToken
|
|
224
|
+
|| op === ts.SyntaxKind.AsteriskToken || op === ts.SyntaxKind.SlashToken
|
|
225
|
+
|| op === ts.SyntaxKind.PercentToken) {
|
|
226
|
+
const l = walkExpr(node.left);
|
|
227
|
+
const r = walkExpr(node.right);
|
|
228
|
+
if (!l.ok || !r.ok)
|
|
229
|
+
return { ok: false };
|
|
230
|
+
const a = l.value;
|
|
231
|
+
const b = r.value;
|
|
232
|
+
if (typeof a !== 'number' || typeof b !== 'number')
|
|
233
|
+
return { ok: false };
|
|
234
|
+
switch (op) {
|
|
235
|
+
case ts.SyntaxKind.PlusToken: return { ok: true, value: a + b };
|
|
236
|
+
case ts.SyntaxKind.MinusToken: return { ok: true, value: a - b };
|
|
237
|
+
case ts.SyntaxKind.AsteriskToken: return { ok: true, value: a * b };
|
|
238
|
+
case ts.SyntaxKind.SlashToken: return { ok: true, value: a / b };
|
|
239
|
+
default: return { ok: true, value: a % b };
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return { ok: false };
|
|
244
|
+
}
|
|
245
|
+
/** The literal walk over an already-parsed node (literalValue on a subnode). */
|
|
246
|
+
function literalOf(node) {
|
|
247
|
+
return walk(node);
|
|
248
|
+
}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseTemplate = parseTemplate;
|
|
4
|
+
const diagnostics_1 = require("../diagnostics");
|
|
5
|
+
const VOID_TAGS = new Set(['img', 'br', 'hr', 'input', 'meta', 'link']);
|
|
6
|
+
/**
|
|
7
|
+
* Recursive-descent parser for Rangular templates.
|
|
8
|
+
* Handles nested + self-closing elements, static attributes, [prop] bindings,
|
|
9
|
+
* (event) bindings, *structural directives, #ref variables, comments
|
|
10
|
+
* (dropped) and {{ interpolation }} inside text. Malformed markup yields
|
|
11
|
+
* diagnostics with line/column, the parser recovers instead of throwing.
|
|
12
|
+
*/
|
|
13
|
+
function parseTemplate(source) {
|
|
14
|
+
const diagnostics = [];
|
|
15
|
+
let i = 0;
|
|
16
|
+
let line = 1;
|
|
17
|
+
let column = 1;
|
|
18
|
+
const pos = () => ({ line, column });
|
|
19
|
+
const eof = () => i >= source.length;
|
|
20
|
+
const startsWith = (s) => source.startsWith(s, i);
|
|
21
|
+
function advance(n) {
|
|
22
|
+
const taken = source.slice(i, i + n);
|
|
23
|
+
for (const ch of taken) {
|
|
24
|
+
if (ch === '\n') {
|
|
25
|
+
line++;
|
|
26
|
+
column = 1;
|
|
27
|
+
}
|
|
28
|
+
else
|
|
29
|
+
column++;
|
|
30
|
+
}
|
|
31
|
+
i += n;
|
|
32
|
+
return taken;
|
|
33
|
+
}
|
|
34
|
+
function skipWhitespace() {
|
|
35
|
+
while (!eof() && /\s/.test(source[i]))
|
|
36
|
+
advance(1);
|
|
37
|
+
}
|
|
38
|
+
function readWhile(pred) {
|
|
39
|
+
let out = '';
|
|
40
|
+
while (!eof() && pred(source[i]))
|
|
41
|
+
out += advance(1);
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
function splitInterpolation(text, at) {
|
|
45
|
+
const parts = [];
|
|
46
|
+
let rest = text;
|
|
47
|
+
for (;;) {
|
|
48
|
+
const open = rest.indexOf('{{');
|
|
49
|
+
if (open === -1)
|
|
50
|
+
break;
|
|
51
|
+
const close = rest.indexOf('}}', open + 2);
|
|
52
|
+
if (close === -1) {
|
|
53
|
+
diagnostics.push((0, diagnostics_1.error)('TPL_INTERPOLATION', 'Unclosed {{ interpolation }}', at.line, at.column, 'Close the interpolation with }}, e.g. {{ title }}'));
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
if (open > 0)
|
|
57
|
+
parts.push({ type: 'static', value: rest.slice(0, open) });
|
|
58
|
+
parts.push({ type: 'expr', expression: rest.slice(open + 2, close).trim() });
|
|
59
|
+
rest = rest.slice(close + 2);
|
|
60
|
+
}
|
|
61
|
+
if (rest)
|
|
62
|
+
parts.push({ type: 'static', value: rest });
|
|
63
|
+
return parts;
|
|
64
|
+
}
|
|
65
|
+
function parseText() {
|
|
66
|
+
const at = pos();
|
|
67
|
+
let raw = '';
|
|
68
|
+
while (!eof() && source[i] !== '<')
|
|
69
|
+
raw += advance(1);
|
|
70
|
+
// Pure layout whitespace between elements is not content.
|
|
71
|
+
if (raw.trim() === '')
|
|
72
|
+
return undefined;
|
|
73
|
+
const leadingWs = raw.length - raw.trimStart().length;
|
|
74
|
+
const trimmed = raw.trim();
|
|
75
|
+
void leadingWs;
|
|
76
|
+
return { type: 'text', parts: splitInterpolation(trimmed, at), pos: at };
|
|
77
|
+
}
|
|
78
|
+
function skipComment() {
|
|
79
|
+
const end = source.indexOf('-->', i + 4);
|
|
80
|
+
if (end === -1) {
|
|
81
|
+
advance(source.length - i);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
advance(end + 3 - i);
|
|
85
|
+
}
|
|
86
|
+
function parseElement() {
|
|
87
|
+
const at = pos();
|
|
88
|
+
advance(1); // '<'
|
|
89
|
+
const tag = readWhile((c) => /[A-Za-z0-9_-]/.test(c));
|
|
90
|
+
if (!tag) {
|
|
91
|
+
diagnostics.push((0, diagnostics_1.error)('TPL_TAG', 'Expected a tag name after <', at.line, at.column, 'Write a real element, e.g. <p>text</p>; a literal < in text is not supported'));
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
const el = {
|
|
95
|
+
type: 'element', tag, attrs: {}, booleanAttrs: [],
|
|
96
|
+
propBindings: [], twoWayBindings: [], eventBindings: [], children: [], pos: at,
|
|
97
|
+
};
|
|
98
|
+
let selfClosing = false;
|
|
99
|
+
for (;;) {
|
|
100
|
+
skipWhitespace();
|
|
101
|
+
if (eof()) {
|
|
102
|
+
diagnostics.push((0, diagnostics_1.error)('TPL_UNCLOSED', `Element <${tag}> is never closed`, at.line, at.column, `Close the element with </${tag}> or make it self-closing: <${tag} />`));
|
|
103
|
+
return el;
|
|
104
|
+
}
|
|
105
|
+
if (startsWith('/>')) {
|
|
106
|
+
advance(2);
|
|
107
|
+
selfClosing = true;
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
if (source[i] === '>') {
|
|
111
|
+
advance(1);
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
parseAttribute(el);
|
|
115
|
+
}
|
|
116
|
+
if (selfClosing || VOID_TAGS.has(tag))
|
|
117
|
+
return el;
|
|
118
|
+
el.children = parseNodes(tag, at);
|
|
119
|
+
return el;
|
|
120
|
+
}
|
|
121
|
+
function parseAttribute(el) {
|
|
122
|
+
const at = pos();
|
|
123
|
+
// Attribute names may start with *, [, ( or # and contain word chars, -, ., [ ] ( ).
|
|
124
|
+
const name = readWhile((c) => /[A-Za-z0-9_\-\.\*\[\]\(\)#]/.test(c));
|
|
125
|
+
if (!name) {
|
|
126
|
+
diagnostics.push((0, diagnostics_1.error)('TPL_ATTR', 'Could not parse an attribute', at.line, at.column, 'Write attributes as name="value", [prop]="expr", (event)="handler()" or *ngIf="cond"'));
|
|
127
|
+
advance(1);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
skipWhitespace();
|
|
131
|
+
let value;
|
|
132
|
+
if (!eof() && source[i] === '=') {
|
|
133
|
+
advance(1);
|
|
134
|
+
skipWhitespace();
|
|
135
|
+
const quote = source[i];
|
|
136
|
+
if (quote === '"' || quote === "'") {
|
|
137
|
+
advance(1);
|
|
138
|
+
let v = '';
|
|
139
|
+
while (!eof() && source[i] !== quote)
|
|
140
|
+
v += advance(1);
|
|
141
|
+
if (!eof())
|
|
142
|
+
advance(1); // closing quote
|
|
143
|
+
value = v;
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
value = readWhile((c) => !/[\s>]/.test(c));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (name.startsWith('*')) {
|
|
150
|
+
const directive = { name: name.slice(1), expression: value ?? '' };
|
|
151
|
+
if (el.structural) {
|
|
152
|
+
// One structural directive per element (the Angular rule, and
|
|
153
|
+
// this AST stores exactly one): the first wins, each later one
|
|
154
|
+
// is dropped with a warning instead of silently overwriting
|
|
155
|
+
// the first, which used to emit the loop variable outside its
|
|
156
|
+
// map (or drop the condition) with no diagnostic at all.
|
|
157
|
+
(el.droppedStructural ??= []).push(directive);
|
|
158
|
+
diagnostics.push((0, diagnostics_1.warning)('TPL_STRUCTURAL_MULTIPLE', `<${el.tag}> carries *${el.structural.name} and *${directive.name}; only the first (*${el.structural.name}) is kept and *${directive.name} is dropped`, at.line, at.column, `Put one structural directive per element: nest one element inside the other, e.g. <div *ngFor="let item of items"><p *ngIf="item.ready">...</p></div>`));
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
el.structural = directive;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
else if (name.startsWith('[(') && name.endsWith(')]')) {
|
|
165
|
+
// Two-way binding [(name)]="expr" (Stage 8): its own list, because
|
|
166
|
+
// codegen must write back, not just bind one way.
|
|
167
|
+
el.twoWayBindings.push({ name: name.slice(2, -2), expression: value ?? '' });
|
|
168
|
+
}
|
|
169
|
+
else if (name.startsWith('[') && name.endsWith(']')) {
|
|
170
|
+
el.propBindings.push({ name: name.slice(1, -1), expression: value ?? '' });
|
|
171
|
+
}
|
|
172
|
+
else if (name.startsWith('(') && name.endsWith(')')) {
|
|
173
|
+
el.eventBindings.push({ name: name.slice(1, -1), expression: value ?? '' });
|
|
174
|
+
}
|
|
175
|
+
else if (name.startsWith('#')) {
|
|
176
|
+
el.ref = name.slice(1);
|
|
177
|
+
// #email="ngModel": the value names what the reference exports.
|
|
178
|
+
if (value !== undefined)
|
|
179
|
+
el.refExport = value;
|
|
180
|
+
}
|
|
181
|
+
else if (value === undefined) {
|
|
182
|
+
el.booleanAttrs.push(name);
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
el.attrs[name] = value;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function parseNodes(untilTag, openPos) {
|
|
189
|
+
const nodes = [];
|
|
190
|
+
while (!eof()) {
|
|
191
|
+
if (startsWith('<!--')) {
|
|
192
|
+
skipComment();
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
if (startsWith('</')) {
|
|
196
|
+
const at = pos();
|
|
197
|
+
advance(2);
|
|
198
|
+
const closing = readWhile((c) => /[A-Za-z0-9_-]/.test(c));
|
|
199
|
+
skipWhitespace();
|
|
200
|
+
if (!eof() && source[i] === '>')
|
|
201
|
+
advance(1);
|
|
202
|
+
if (untilTag === undefined) {
|
|
203
|
+
diagnostics.push((0, diagnostics_1.error)('TPL_CLOSE', `Unexpected closing tag </${closing}>`, at.line, at.column, `Remove the stray </${closing}> or add its opening <${closing}> before it`));
|
|
204
|
+
return nodes;
|
|
205
|
+
}
|
|
206
|
+
if (closing !== untilTag) {
|
|
207
|
+
diagnostics.push((0, diagnostics_1.error)('TPL_MISMATCH', `Expected </${untilTag}> but found </${closing}>`, at.line, at.column, VOID_TAGS.has(closing.toLowerCase())
|
|
208
|
+
? `<${closing}> is a void element and takes no closing tag; remove the </${closing}>`
|
|
209
|
+
: `Close <${untilTag}> with </${untilTag}>, check for a missing or mis-nested closing tag above`));
|
|
210
|
+
}
|
|
211
|
+
return nodes;
|
|
212
|
+
}
|
|
213
|
+
if (source[i] === '<') {
|
|
214
|
+
const el = parseElement();
|
|
215
|
+
if (el)
|
|
216
|
+
nodes.push(el);
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
const text = parseText();
|
|
220
|
+
if (text)
|
|
221
|
+
nodes.push(text);
|
|
222
|
+
}
|
|
223
|
+
if (untilTag !== undefined) {
|
|
224
|
+
diagnostics.push((0, diagnostics_1.error)('TPL_UNCLOSED', `Element <${untilTag}> is never closed`, openPos.line, openPos.column, `Add the missing closing tag </${untilTag}>`));
|
|
225
|
+
}
|
|
226
|
+
return nodes;
|
|
227
|
+
}
|
|
228
|
+
const children = parseNodes(undefined, { line: 1, column: 1 });
|
|
229
|
+
return { root: { type: 'root', children }, diagnostics };
|
|
230
|
+
}
|