@rangular-framework/compiler 0.0.0-stage → 1.0.1

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.
Files changed (68) hide show
  1. package/dist/compiler/src/catalog.d.ts +63 -0
  2. package/dist/compiler/src/catalog.js +198 -0
  3. package/dist/compiler/src/class/formInit.d.ts +119 -0
  4. package/dist/compiler/src/class/formInit.js +370 -0
  5. package/dist/compiler/src/class/parseComponent.d.ts +232 -0
  6. package/dist/compiler/src/class/parseComponent.js +430 -0
  7. package/dist/compiler/src/class/parseDirective.d.ts +42 -0
  8. package/dist/compiler/src/class/parseDirective.js +227 -0
  9. package/dist/compiler/src/class/parseRoutes.d.ts +59 -0
  10. package/dist/compiler/src/class/parseRoutes.js +163 -0
  11. package/dist/compiler/src/codegen/generate.d.ts +166 -0
  12. package/dist/compiler/src/codegen/generate.js +3466 -0
  13. package/dist/compiler/src/codegen/methods.d.ts +148 -0
  14. package/dist/compiler/src/codegen/methods.js +975 -0
  15. package/dist/compiler/src/codegen/sourceMap.d.ts +42 -0
  16. package/dist/compiler/src/codegen/sourceMap.js +77 -0
  17. package/dist/compiler/src/compile.d.ts +101 -0
  18. package/dist/compiler/src/compile.js +775 -0
  19. package/dist/compiler/src/diagnostics.d.ts +37 -0
  20. package/dist/compiler/src/diagnostics.js +113 -0
  21. package/dist/compiler/src/doctor.d.ts +35 -0
  22. package/dist/compiler/src/doctor.js +144 -0
  23. package/dist/compiler/src/fix.d.ts +21 -0
  24. package/dist/compiler/src/fix.js +44 -0
  25. package/dist/compiler/src/index.d.ts +22 -0
  26. package/dist/compiler/src/index.js +38 -0
  27. package/dist/compiler/src/preview/renderPreview.d.ts +101 -0
  28. package/dist/compiler/src/preview/renderPreview.js +7158 -0
  29. package/dist/compiler/src/preview/styleSnapshot.d.ts +36 -0
  30. package/dist/compiler/src/preview/styleSnapshot.js +268 -0
  31. package/dist/compiler/src/propTable.d.ts +22 -0
  32. package/dist/compiler/src/propTable.js +107 -0
  33. package/dist/compiler/src/style/css.d.ts +23 -0
  34. package/dist/compiler/src/style/css.js +161 -0
  35. package/dist/compiler/src/template/ast.d.ts +66 -0
  36. package/dist/compiler/src/template/ast.js +19 -0
  37. package/dist/compiler/src/template/evaluate.d.ts +45 -0
  38. package/dist/compiler/src/template/evaluate.js +151 -0
  39. package/dist/compiler/src/template/expr.d.ts +94 -0
  40. package/dist/compiler/src/template/expr.js +360 -0
  41. package/dist/compiler/src/template/forms.d.ts +42 -0
  42. package/dist/compiler/src/template/forms.js +80 -0
  43. package/dist/compiler/src/template/literal.d.ts +38 -0
  44. package/dist/compiler/src/template/literal.js +248 -0
  45. package/dist/compiler/src/template/parser.d.ts +14 -0
  46. package/dist/compiler/src/template/parser.js +230 -0
  47. package/dist/compiler/src/template/pipes.d.ts +48 -0
  48. package/dist/compiler/src/template/pipes.js +225 -0
  49. package/dist/compiler/src/template/printAst.d.ts +3 -0
  50. package/dist/compiler/src/template/printAst.js +38 -0
  51. package/dist/compiler/src/template/structural.d.ts +27 -0
  52. package/dist/compiler/src/template/structural.js +51 -0
  53. package/dist/runtime/src/index.d.ts +486 -0
  54. package/dist/runtime/src/index.js +1197 -0
  55. package/dist/ui/src/chart.d.ts +81 -0
  56. package/dist/ui/src/chart.js +196 -0
  57. package/dist/ui/src/datetime.d.ts +92 -0
  58. package/dist/ui/src/datetime.js +240 -0
  59. package/dist/ui/src/icons.d.ts +63 -0
  60. package/dist/ui/src/icons.js +310 -0
  61. package/dist/ui/src/mask.d.ts +38 -0
  62. package/dist/ui/src/mask.js +103 -0
  63. package/dist/ui/src/palette.d.ts +66 -0
  64. package/dist/ui/src/palette.js +141 -0
  65. package/dist/ui/src/tokens.d.ts +129 -0
  66. package/dist/ui/src/tokens.js +173 -0
  67. package/package.json +24 -4
  68. package/README.md +0 -3
@@ -0,0 +1,66 @@
1
+ /** AST types for Rangular templates. */
2
+ export interface SourcePos {
3
+ line: number;
4
+ column: number;
5
+ }
6
+ export interface PropBinding {
7
+ name: string;
8
+ expression: string;
9
+ }
10
+ export interface EventBinding {
11
+ name: string;
12
+ expression: string;
13
+ }
14
+ export interface StructuralDirective {
15
+ /** e.g. 'ngIf' or 'ngFor' (without the leading '*'). */
16
+ name: string;
17
+ expression: string;
18
+ }
19
+ export interface ElementNode {
20
+ type: 'element';
21
+ tag: string;
22
+ /** Static attributes, e.g. class="card" title="Hi". Insertion order preserved. */
23
+ attrs: Record<string, string>;
24
+ /** Attributes present without a value, e.g. `avatar`. */
25
+ booleanAttrs: string[];
26
+ propBindings: PropBinding[];
27
+ /** Two-way bindings from `[(name)]="expr"` (Stage 8); kept apart from
28
+ * propBindings because a two-way binding also writes back. */
29
+ twoWayBindings: PropBinding[];
30
+ eventBindings: EventBinding[];
31
+ structural?: StructuralDirective;
32
+ /**
33
+ * Structural directives the parser dropped because the element
34
+ * already carried one (one structural directive per element): the
35
+ * parser warns TPL_STRUCTURAL_MULTIPLE for each, and codegen emits
36
+ * a TODO comment naming each dropped directive.
37
+ */
38
+ droppedStructural?: StructuralDirective[];
39
+ /** Template reference variable name from `#ref`, without '#'. */
40
+ ref?: string;
41
+ /** The exportAs value of a template reference, e.g. `#email="ngModel"` (Stage 8). */
42
+ refExport?: string;
43
+ children: TemplateNode[];
44
+ pos: SourcePos;
45
+ }
46
+ export type TextPart = {
47
+ type: 'static';
48
+ value: string;
49
+ } | {
50
+ type: 'expr';
51
+ expression: string;
52
+ };
53
+ export interface TextNode {
54
+ type: 'text';
55
+ parts: TextPart[];
56
+ pos: SourcePos;
57
+ }
58
+ export type TemplateNode = ElementNode | TextNode;
59
+ export interface TemplateRoot {
60
+ type: 'root';
61
+ children: TemplateNode[];
62
+ }
63
+ export declare function isElement(node: TemplateNode): node is ElementNode;
64
+ export declare function isText(node: TemplateNode): node is TextNode;
65
+ /** The full text of a TextNode if it is purely static, else undefined. */
66
+ export declare function staticText(node: TextNode): string | undefined;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ /** AST types for Rangular templates. */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.isElement = isElement;
5
+ exports.isText = isText;
6
+ exports.staticText = staticText;
7
+ function isElement(node) {
8
+ return node.type === 'element';
9
+ }
10
+ function isText(node) {
11
+ return node.type === 'text';
12
+ }
13
+ /** The full text of a TextNode if it is purely static, else undefined. */
14
+ function staticText(node) {
15
+ if (node.parts.every((p) => p.type === 'static')) {
16
+ return node.parts.map((p) => p.value).join('');
17
+ }
18
+ return undefined;
19
+ }
@@ -0,0 +1,45 @@
1
+ import { Expr } from './expr';
2
+ export type Scope = Record<string, unknown>;
3
+ /**
4
+ * Custom pipe functions by pipe name (Stage 12): a @Pipe class's
5
+ * transform, supplied by whoever owns the compilation (the preview
6
+ * builds them from the resolved pipe classes). The evaluator stays a
7
+ * pure walker; it never sees TypeScript source.
8
+ */
9
+ export type PipeFunctions = Record<string, (value: unknown, ...args: unknown[]) => unknown>;
10
+ /**
11
+ * Evaluate a parsed template expression against a scope object.
12
+ * This walks the expression AST produced by the Pratt parser, it never
13
+ * uses eval/Function on source text.
14
+ *
15
+ * Semantics follow Angular templates pragmatically:
16
+ * - unknown identifiers evaluate to undefined;
17
+ * - member/index access on null/undefined evaluates to undefined;
18
+ * - method calls through a member (obj.fn()) keep `obj` as `this`;
19
+ * - built-in pipes: uppercase, lowercase, titlecase, json.
20
+ * Unknown pipes throw a clear error.
21
+ */
22
+ /**
23
+ * Evaluate a parsed template expression against a scope object.
24
+ * This walks the expression AST produced by the Pratt parser, it never
25
+ * uses eval/Function on source text.
26
+ *
27
+ * Semantics follow Angular templates pragmatically:
28
+ * - unknown identifiers evaluate to undefined;
29
+ * - member/index access on null/undefined evaluates to undefined;
30
+ * - method calls through a member (obj.fn()) keep `obj` as `this`;
31
+ * - built-in pipes: the Stage 12 set in template/pipes.ts
32
+ * (uppercase, lowercase, titlecase, json, date, number, percent,
33
+ * currency, slice, keyvalue, async), plus any custom pipes the
34
+ * caller supplies. Unknown pipes throw a clear error.
35
+ *
36
+ * `refs` (Stage 8) carries template reference variables: when the base
37
+ * of a member chain is a reference name (an ngModel input ref like
38
+ * `#email="ngModel"`), the chain reads from the reference object
39
+ * (its live validation state), not from the scope field of the same
40
+ * name. A bare reference identifier still resolves in the scope, exactly
41
+ * like the generated code, where only chain roots are rewritten.
42
+ */
43
+ export declare function evaluateExpression(source: string, scope: Scope, refs?: Scope, pipes?: PipeFunctions): unknown;
44
+ export declare function evaluateExpr(expr: Expr, scope: Scope, refs?: Scope, pipes?: PipeFunctions): unknown;
45
+ export declare function applyPipe(name: string, value: unknown, args?: unknown[], pipes?: PipeFunctions): unknown;
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.evaluateExpression = evaluateExpression;
4
+ exports.evaluateExpr = evaluateExpr;
5
+ exports.applyPipe = applyPipe;
6
+ const expr_1 = require("./expr");
7
+ const pipes_1 = require("./pipes");
8
+ /**
9
+ * Evaluate a parsed template expression against a scope object.
10
+ * This walks the expression AST produced by the Pratt parser, it never
11
+ * uses eval/Function on source text.
12
+ *
13
+ * Semantics follow Angular templates pragmatically:
14
+ * - unknown identifiers evaluate to undefined;
15
+ * - member/index access on null/undefined evaluates to undefined;
16
+ * - method calls through a member (obj.fn()) keep `obj` as `this`;
17
+ * - built-in pipes: uppercase, lowercase, titlecase, json.
18
+ * Unknown pipes throw a clear error.
19
+ */
20
+ /**
21
+ * Evaluate a parsed template expression against a scope object.
22
+ * This walks the expression AST produced by the Pratt parser, it never
23
+ * uses eval/Function on source text.
24
+ *
25
+ * Semantics follow Angular templates pragmatically:
26
+ * - unknown identifiers evaluate to undefined;
27
+ * - member/index access on null/undefined evaluates to undefined;
28
+ * - method calls through a member (obj.fn()) keep `obj` as `this`;
29
+ * - built-in pipes: the Stage 12 set in template/pipes.ts
30
+ * (uppercase, lowercase, titlecase, json, date, number, percent,
31
+ * currency, slice, keyvalue, async), plus any custom pipes the
32
+ * caller supplies. Unknown pipes throw a clear error.
33
+ *
34
+ * `refs` (Stage 8) carries template reference variables: when the base
35
+ * of a member chain is a reference name (an ngModel input ref like
36
+ * `#email="ngModel"`), the chain reads from the reference object
37
+ * (its live validation state), not from the scope field of the same
38
+ * name. A bare reference identifier still resolves in the scope, exactly
39
+ * like the generated code, where only chain roots are rewritten.
40
+ */
41
+ function evaluateExpression(source, scope, refs, pipes) {
42
+ return evaluateExpr((0, expr_1.parseExpression)(source), scope, refs, pipes);
43
+ }
44
+ function evaluateExpr(expr, scope, refs, pipes) {
45
+ switch (expr.type) {
46
+ case 'literal':
47
+ return expr.value;
48
+ case 'identifier':
49
+ return scope[expr.name];
50
+ case 'member': {
51
+ if (expr.object.type === 'identifier' && refs
52
+ && Object.prototype.hasOwnProperty.call(refs, expr.object.name)) {
53
+ const base = refs[expr.object.name];
54
+ if (base === null || base === undefined)
55
+ return undefined;
56
+ return base[expr.property];
57
+ }
58
+ const obj = evaluateExpr(expr.object, scope, refs, pipes);
59
+ if (obj === null || obj === undefined)
60
+ return undefined;
61
+ return obj[expr.property];
62
+ }
63
+ case 'index': {
64
+ const obj = evaluateExpr(expr.object, scope, refs, pipes);
65
+ if (obj === null || obj === undefined)
66
+ return undefined;
67
+ const key = evaluateExpr(expr.index, scope, refs, pipes);
68
+ return obj[key];
69
+ }
70
+ case 'call': {
71
+ const args = expr.args.map((a) => evaluateExpr(a, scope, refs, pipes));
72
+ if (expr.callee.type === 'member') {
73
+ const obj = evaluateExpr(expr.callee.object, scope, refs, pipes);
74
+ if (obj === null || obj === undefined)
75
+ return undefined;
76
+ const fn = obj[expr.callee.property];
77
+ if (typeof fn !== 'function') {
78
+ throw new Error(`Expression error: '${expr.callee.property}' is not a function`);
79
+ }
80
+ return fn.apply(obj, args);
81
+ }
82
+ const fn = evaluateExpr(expr.callee, scope, refs, pipes);
83
+ if (typeof fn !== 'function') {
84
+ throw new Error('Expression error: attempted to call a non-function value');
85
+ }
86
+ return fn(...args);
87
+ }
88
+ case 'unary': {
89
+ const v = evaluateExpr(expr.argument, scope, refs, pipes);
90
+ if (expr.op === '!')
91
+ return !v;
92
+ if (expr.op === '-')
93
+ return -v;
94
+ if (expr.op === '+')
95
+ return +v;
96
+ throw new Error(`Expression error: unsupported unary operator '${expr.op}'`);
97
+ }
98
+ case 'binary':
99
+ return evaluateBinary(expr.op, expr.left, expr.right, scope, refs, pipes);
100
+ case 'conditional':
101
+ return evaluateExpr(expr.test, scope, refs, pipes)
102
+ ? evaluateExpr(expr.consequent, scope, refs, pipes)
103
+ : evaluateExpr(expr.alternate, scope, refs, pipes);
104
+ case 'array':
105
+ return expr.elements.map((el) => evaluateExpr(el, scope, refs, pipes));
106
+ case 'pipe': {
107
+ const value = evaluateExpr(expr.input, scope, refs, pipes);
108
+ const args = expr.args.map((a) => evaluateExpr(a, scope, refs, pipes));
109
+ return applyPipe(expr.name, value, args, pipes);
110
+ }
111
+ }
112
+ }
113
+ function evaluateBinary(op, left, right, scope, refs, pipes) {
114
+ // Short-circuiting operators return operand values, like JavaScript.
115
+ if (op === '&&') {
116
+ const l = evaluateExpr(left, scope, refs, pipes);
117
+ return l ? evaluateExpr(right, scope, refs, pipes) : l;
118
+ }
119
+ if (op === '||') {
120
+ const l = evaluateExpr(left, scope, refs, pipes);
121
+ return l ? l : evaluateExpr(right, scope, refs, pipes);
122
+ }
123
+ const l = evaluateExpr(left, scope, refs, pipes);
124
+ const r = evaluateExpr(right, scope, refs, pipes);
125
+ switch (op) {
126
+ case '+': return l + r;
127
+ case '-': return l - r;
128
+ case '*': return l * r;
129
+ case '/': return l / r;
130
+ case '%': return l % r;
131
+ // eslint-disable-next-line eqeqeq -- Angular templates use JS loose equality for ==
132
+ case '==': return l == r; // NOSONAR
133
+ case '===': return l === r;
134
+ // eslint-disable-next-line eqeqeq -- see above
135
+ case '!=': return l != r; // NOSONAR
136
+ case '!==': return l !== r;
137
+ case '<': return l < r;
138
+ case '>': return l > r;
139
+ case '<=': return l <= r;
140
+ case '>=': return l >= r;
141
+ default: throw new Error(`Expression error: unsupported binary operator '${op}'`);
142
+ }
143
+ }
144
+ function applyPipe(name, value, args = [], pipes) {
145
+ if (pipes && Object.prototype.hasOwnProperty.call(pipes, name)) {
146
+ return pipes[name](value, ...args);
147
+ }
148
+ if ((0, pipes_1.isBuiltinPipe)(name))
149
+ return (0, pipes_1.applyBuiltinPipe)(name, value, args);
150
+ throw new Error(`Unknown pipe '${name}'`);
151
+ }
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Pratt parser for template expressions: `{{ a + b * c }}`, `user.name`,
3
+ * `save($event)`, `cond ? a : b`, `items | async`, `name | uppercase:'x'`.
4
+ *
5
+ * Precedence (lowest to highest): pipe | ternary ?: | || | && |
6
+ * equality (== === != !==) | relational (< > <= >=) | additive (+ -) |
7
+ * multiplicative (* / %) | unary (! -) | call/member | primary.
8
+ */
9
+ export type Expr = {
10
+ type: 'identifier';
11
+ name: string;
12
+ } | {
13
+ type: 'literal';
14
+ value: string | number | boolean | null;
15
+ raw: string;
16
+ } | {
17
+ type: 'member';
18
+ object: Expr;
19
+ property: string;
20
+ } | {
21
+ type: 'index';
22
+ object: Expr;
23
+ index: Expr;
24
+ } | {
25
+ type: 'call';
26
+ callee: Expr;
27
+ args: Expr[];
28
+ } | {
29
+ type: 'unary';
30
+ op: string;
31
+ argument: Expr;
32
+ } | {
33
+ type: 'binary';
34
+ op: string;
35
+ left: Expr;
36
+ right: Expr;
37
+ } | {
38
+ type: 'conditional';
39
+ test: Expr;
40
+ consequent: Expr;
41
+ alternate: Expr;
42
+ } | {
43
+ type: 'array';
44
+ elements: Expr[];
45
+ } | {
46
+ type: 'pipe';
47
+ input: Expr;
48
+ name: string;
49
+ args: Expr[];
50
+ };
51
+ export declare function parseExpression(source: string): Expr;
52
+ /** Canonical, fully-parenthesised string form, used by tests and codegen. */
53
+ export declare function exprToString(expr: Expr): string;
54
+ /**
55
+ * Options for exprToCode (Stage 8, forms):
56
+ * - renames: identifier -> replacement code, applied at every identifier
57
+ * leaf. Codegen uses it for reactive form fields, whose template reads
58
+ * (`profileForm.value`) must reach the ref-held instance
59
+ * (`profileFormRef.current.value`).
60
+ * - refBases: template reference name -> generated model object name.
61
+ * Only the ROOT of a member/index/call chain is renamed: `email.invalid`
62
+ * becomes `emailModel.invalid`, while a bare `email` still names the
63
+ * component field itself.
64
+ */
65
+ export interface ExprToCodeOptions {
66
+ renames?: Map<string, string>;
67
+ refBases?: Map<string, string>;
68
+ /**
69
+ * Custom @Pipe classes (Stage 12): pipe name -> the generated
70
+ * instance variable holding the pipe (`__pipeExclaim`). A pipe use
71
+ * becomes `<instance>.transform(input, ...args)` instead of the
72
+ * runtime pipe() helper.
73
+ */
74
+ customPipes?: Map<string, string>;
75
+ /**
76
+ * Async pipe hoisting (Stage 12): the generated code string of an
77
+ * async pipe's input expression -> the state variable the generated
78
+ * subscription hook fills. An `expr | async` whose input code is a
79
+ * key here compiles to just that variable; the hook lives at the top
80
+ * of the generated component.
81
+ */
82
+ asyncVars?: Map<string, string>;
83
+ }
84
+ /**
85
+ * Translate a template expression into generated-code source.
86
+ * Built-in pipes are emitted as a call to the runtime
87
+ * `pipe(name, value, ...args)` helper; custom @Pipe classes (Stage 12)
88
+ * become a transform call on the generated pipe instance, and an
89
+ * `| async` whose input the generator hoisted becomes the hook's
90
+ * state variable.
91
+ */
92
+ export declare function exprToCode(source: string, options?: ExprToCodeOptions): string;
93
+ /** Translate an already-parsed expression (Stage 12: the pipe scan shares it). */
94
+ export declare function exprAstToCode(exprIn: Expr, options?: ExprToCodeOptions): string;