@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,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DIAGNOSTIC_CODES = void 0;
|
|
4
|
+
exports.error = error;
|
|
5
|
+
exports.warning = warning;
|
|
6
|
+
exports.formatDiagnostic = formatDiagnostic;
|
|
7
|
+
function error(code, message, line, column, fix) {
|
|
8
|
+
return { severity: 'error', code, message, line, column, fix };
|
|
9
|
+
}
|
|
10
|
+
function warning(code, message, line, column, fix) {
|
|
11
|
+
return { severity: 'warning', code, message, line, column, fix };
|
|
12
|
+
}
|
|
13
|
+
function formatDiagnostic(d, entryFile) {
|
|
14
|
+
const where = d.line !== undefined ? ` (${d.line}:${d.column ?? 1})` : '';
|
|
15
|
+
// The file is printed only when it differs from the file the user asked
|
|
16
|
+
// about, so single-file output stays as terse as before (Stage 5).
|
|
17
|
+
const fileNote = d.file && d.file !== entryFile ? ` [in ${d.file}]` : '';
|
|
18
|
+
const head = `${d.severity.toUpperCase()} ${d.code}${where}: ${d.message}${fileNote}`;
|
|
19
|
+
return d.fix ? `${head}\n fix: ${d.fix}` : head;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Every diagnostic code the compiler can emit, with its meaning.
|
|
23
|
+
* Single source of truth: the catalog is generated from this list.
|
|
24
|
+
*/
|
|
25
|
+
exports.DIAGNOSTIC_CODES = {
|
|
26
|
+
TPL_INTERPOLATION: 'A {{ interpolation in a template is never closed with }}.',
|
|
27
|
+
TPL_TAG: 'A "<" in a template is not followed by a tag name.',
|
|
28
|
+
TPL_UNCLOSED: 'An element is opened but never closed.',
|
|
29
|
+
TPL_ATTR: 'An attribute in a template could not be parsed.',
|
|
30
|
+
TPL_CLOSE: 'A closing tag appears with no matching opening element.',
|
|
31
|
+
TPL_MISMATCH: 'A closing tag does not match the currently open element.',
|
|
32
|
+
TPL_NGFOR: 'The *ngFor microsyntax could not be parsed.',
|
|
33
|
+
TPL_NGFOR_SEGMENT: 'A segment of *ngFor microsyntax is not supported and was ignored.',
|
|
34
|
+
TPL_STRUCTURAL_MULTIPLE: 'An element carries more than one structural directive (*ngIf, *ngFor, ...); only the first is kept and each later one is dropped. One structural directive per element: nest one element inside the other.',
|
|
35
|
+
CLS_NO_COMPONENT: 'No class decorated with @Component was found in the source file.',
|
|
36
|
+
CLS_PARSE: 'The TypeScript source has a syntax error. TypeScript reads on with error recovery, so classes and fields after the error can be silently missing or misread; the compiler reports the parse error itself instead of guessing.',
|
|
37
|
+
GEN_SETTER_COLLISION: 'A component method has the same name as a generated state setter (set + a field name, or a form field touched setter). The generated code would declare the name twice and one would overwrite the other, so the method must be renamed.',
|
|
38
|
+
GEN_IMPORT_CLASSLESS: 'A relative import binds names from a file that declares no component, service, pipe or directive. Exported constants with literal values in such a file are carried into the generated code (0.6.5); any other name used from it would be undefined at run time, so the compiler reports the import instead of dropping it silently.',
|
|
39
|
+
CMP_TEMPLATE: 'The component template could not be resolved (missing inline template and templateUrl).',
|
|
40
|
+
CSS_SELECTOR: 'A CSS selector is not an element or .class selector; the rule was skipped.',
|
|
41
|
+
CSS_DECL: 'A CSS declaration is malformed (expected "property: value").',
|
|
42
|
+
CSS_UNSUPPORTED: 'A CSS property is outside the supported subset; the declaration was dropped.',
|
|
43
|
+
STYLE_OFF_SCALE: 'A spacing, radius or font-size value is off its design-token scale; the generated style uses the nearest on-scale value.',
|
|
44
|
+
GEN_UNKNOWN_TAG: 'A template tag is not a known Rangular block; it was emitted as <View>.',
|
|
45
|
+
TPL_HANDLER: 'A template event binding names a method the component does not have; the handler would fail when the event fires.',
|
|
46
|
+
TPL_NESTED_SCREEN: 'A screen sits inside another screen in the same template; it renders embedded, as a flat themed region with no scroller of its own, so its scroll, refresh and end-reached settings have no effect.',
|
|
47
|
+
GEN_UNKNOWN_PROP: 'An attribute or binding on a known element is not one of that element\'s props; it would be passed through and ignored.',
|
|
48
|
+
GEN_FIELD_REREAD: 'A method assigns a field, reads it, then assigns it again; the read sees the value from before the method ran, not the assigned value.',
|
|
49
|
+
GEN_TIMER_STALE: 'A timer created in ngOnInit or the constructor keeps the first render\'s field values; a callback that reads a component field reads the first value forever, so the display freezes or acts on stale state.',
|
|
50
|
+
GEN_DEEP_MUTATION: 'An assignment into a field\'s insides (an index or a property of the field) changes the data without the generated setter, so the view never re-renders; assign a new array or object to the field instead.',
|
|
51
|
+
GEN_LIST_CONTRACT_CLASH: 'A list that declares both (refresh) and (endReached) keeps only the end-reached contract; its pull-to-refresh never engages.',
|
|
52
|
+
GEN_LIST_DUPLICATE: 'Two lists in one template declare the same scroll contract; a screen lends its refresh and end-reached handling to one list each, and the last one registered wins in silence.',
|
|
53
|
+
GEN_NAV_UNDECLARED: 'A navigate call names a path no route declares; with no wildcard route the tap lands on a blank page.',
|
|
54
|
+
GEN_ROUTER_NO_OUTLET: 'The root component template carries a <screen> and routing is on, but no <router-outlet>; the generated screen reads the current route for its scroll key, and only the outlet creates that route value, so the app throws at startup and shows a blank page.',
|
|
55
|
+
GEN_FIELD: 'A field has a non-literal initializer that cannot be emitted verbatim into the generated component (it references this, or the field is assigned in a method); it is declared as undefined there so the output still compiles. A never-assigned non-literal initializer without this (new Date(), Date.now(), an expression over literals) is emitted verbatim and does not warn.',
|
|
56
|
+
GEN_FIELD_STATE: 'A field is assigned in a method but has a non-literal initializer, so it cannot become useState yet.',
|
|
57
|
+
GEN_SIGNAL_SCOPE: 'A computed() initializer reads something other than signal or computed fields and injected services (a plain field, a method, or anything else on this); the computed value cannot track those, so the field is declared as undefined in the generated component. Read signals and service signals inside computed; derive from plain fields with a method instead.',
|
|
58
|
+
GEN_SIGNAL_EFFECT_CONTEXT: 'effect() is called outside the constructor or ngOnInit; the effect still runs, but it is not destroyed when the component is destroyed, so it keeps running for the life of the app. Create effects in the constructor or ngOnInit so they are destroyed with the component.',
|
|
59
|
+
GEN_NGIF_ELSE_TODO: '*ngIf with else/then microsyntax is not generated yet; the element was emitted unconditionally.',
|
|
60
|
+
GEN_STRUCTURAL_TODO: 'A structural directive other than *ngIf/*ngFor is not supported yet; the element was emitted unconditionally.',
|
|
61
|
+
GEN_CONTROL_NESTING: 'A declaration is nested in the wrong parent; option belongs in switcher or select, radio belongs in radio-group, tab belongs in tabs, column belongs in table, step belongs in stepper, menu-item belongs in menu, grid-tile belongs in grid-list, tree-node belongs in tree or another tree-node, nav-item belongs in bottom-nav, row-action belongs in row, timeline-item belongs in timeline, avatar belongs in avatar-group, and crumb belongs in breadcrumbs, and those groups (plus accordion, which takes panels only, and menu, which also takes dividers) accept only their own declarations.',
|
|
62
|
+
GEN_ICON_UNKNOWN: 'An <icon> names an icon that is not in the Rangular icon set; the JSON form of this diagnostic carries the full valid list in validIcons.',
|
|
63
|
+
GEN_ICON_NAME: 'An <icon> element has no name attribute and no [name] binding, so there is nothing to draw.',
|
|
64
|
+
GEN_ICON_SIZE: 'An <icon> size is off the icon size scale (20, 24, 28); the generated code uses the nearest on-scale size.',
|
|
65
|
+
GEN_NGMODEL_TARGET: 'ngModel (two-way, [ngModel] or (ngModelChange)) is used on an element other than <input>; in this version ngModel binds text inputs only.',
|
|
66
|
+
GEN_NGMODEL_EXPR: 'An ngModel binding does not target a plain component field with a literal initial value, so no write-back or validation state could be generated; the value is bound one way.',
|
|
67
|
+
GEN_FORM_CONTROL: 'A formControlName cannot be bound: the input is not inside a <form> with a [formGroup], the control name is not one of the group\'s controls, or formControlName was written as a [binding] instead of a static attribute.',
|
|
68
|
+
GEN_FORMGROUP_TYPE: 'A [formGroup] binding does not name a field initialised with new FormGroup(...), so the reactive form cannot be wired.',
|
|
69
|
+
GEN_FORM_INITIALIZER: 'A field initialised with a form tree (new FormGroup/FormControl/FormArray(...) or a FormBuilder group/control/array call) uses a shape the preview cannot evaluate (only literal values, Validators references and calls, nested groups and arrays, and builder tuples are supported); the generated app runs the initializer as written.',
|
|
70
|
+
GEN_FORM_ARRAY: 'A formArrayName cannot be bound: it is not inside a <form> with a [formGroup], the name is not one of the group\'s controls, or that control is not a FormArray; or a static formControlName inside a formArrayName container names a row instead of numbering it.',
|
|
71
|
+
GEN_ROUTES_MISSING: 'A template uses <router-outlet> or routerLink, or a component injects Router or ActivatedRoute, but no routes file was resolved: the compiler looks for app.routes.ts next to the root component, or the file named by the CLI --routes flag.',
|
|
72
|
+
GEN_ROUTE_COMPONENT: 'A route entry names a component class that is not an @Component class resolved in this compilation.',
|
|
73
|
+
GEN_ROUTE_DUPLICATE: 'Two route entries declare the same path; matching tries entries in order, so the first one wins and the later one never renders.',
|
|
74
|
+
GEN_ROUTE_UNSUPPORTED: 'A route entry or routing construct uses an Angular routing feature Rangular does not support yet (child routes, guards, resolvers, lazy loading, nested outlets, routerLink on a component tag), or a route entry is not a plain object literal with a string path.',
|
|
75
|
+
GEN_PICKER_MODE: 'A <datetime-picker> mode is not one of the three picker modes (date, time, datetime).',
|
|
76
|
+
GEN_PICKER_PRESENTATION: 'A <datetime-picker> carries a presentation attribute; the picker always opens in a modal and takes no presentation.',
|
|
77
|
+
GEN_BUTTON_COLOR: 'A <button> color is not one of the six colour roles (primary, secondary, danger, warning, success, neutral); the button keeps the primary colour.',
|
|
78
|
+
GEN_SWITCH_COLOR: 'A <switch> color is not one of the two colour roles (primary, success); the switch keeps the primary colour.',
|
|
79
|
+
GEN_CHART_TYPE: 'A <chart> type is not one of the three chart types (bar, line, pie); the chart would draw bars instead.',
|
|
80
|
+
GEN_OTP_LENGTH: 'An <otp> length is outside the supported 4 to 8; the generated control clamps it to the nearest of the two.',
|
|
81
|
+
GEN_PICKER_INTERVAL: 'A <datetime-picker> minuteInterval is not 1 or 5; the generated code uses the nearest of the two.',
|
|
82
|
+
GEN_OVERLAY_OPEN: 'A <sheet>, <dialog>, <menu>, <drawer> or <lightbox> has no [open] binding, so it cannot be opened or closed from the component; it renders statically open.',
|
|
83
|
+
GEN_TOOLTIP_HOST: 'A tooltip attribute or [tooltip] binding sits on an element that cannot host a tooltip in this version (button, row and icon-button can); the tooltip was dropped.',
|
|
84
|
+
GEN_EVENT_ASSIGNMENT: 'An event binding holds an assignment statement (for example (close)="sheetOpen = false"); template event bindings take a method call, never an assignment, so the binding was dropped.',
|
|
85
|
+
GEN_TABLE_COLUMN: 'A <column> has no name attribute (or key alias) naming the row property it displays, so the table cannot read its cells.',
|
|
86
|
+
GEN_SLIDER_RANGE: 'A <slider> range is unusable: min must be below max (an error, checked when both are statically known), and step must be above zero (a warning; the generated code uses 1).',
|
|
87
|
+
GEN_PROGRESS_RANGE: 'A <progress-bar> value is statically known to sit outside 0 to 100; the generated code clamps it into range.',
|
|
88
|
+
GEN_SPINNER_SIZE: 'A <spinner> size is off the icon size scale (20, 24, 28); the generated code uses the nearest on-scale size.',
|
|
89
|
+
GEN_BADGE_HOST: 'A badge attribute or [badge] binding sits on an element that cannot host a badge in this version (button, row, icon and nav-item can); the badge was dropped.',
|
|
90
|
+
GEN_CLASS_BINDING: 'A class binding Rangular cannot honour was dropped: [class] and [ngClass] bind a whole dynamic class value, which cannot be resolved to StyleSheet entries at compile time, and [class.name] only works when the component styles declare that class and the block takes a style. The supported toggle is [class.name]="cond" over a class declared in the component styles; the other working pattern is named classes in the component styles with the plain class attribute, swapped with *ngIf.',
|
|
91
|
+
GEN_STYLE_BINDING: 'A style binding or static style attribute was dropped: [style], [style.prop] (with or without a unit) and [ngStyle] bind raw CSS values, which bypass the token-snapped component styles, and a static style="..." attribute has no StyleSheet entry to attach to. Styles live in the component styles block under a class, applied with the plain class attribute or toggled with [class.name].',
|
|
92
|
+
GEN_ATTR_BINDING: 'An [attr.x] binding was dropped: it targets an HTML attribute, and React Native elements have no arbitrary attributes. Use the plain attribute when the block supports one, or the specific [prop] binding the block documents.',
|
|
93
|
+
GEN_IMPORT_COLLISION: 'A third-party import binding was dropped because its local name is already taken in the generated module: by the same name imported from a different module, or by a name the generated module itself defines (a generated class or component function, or one of its own framework imports). Emitting it would duplicate the name and break the module; the first binding of the name wins.',
|
|
94
|
+
METHOD_UNSUPPORTED: 'A statement in a component method is outside the supported translation subset; it was left as a TODO.',
|
|
95
|
+
CMP_IMPORT_UNRESOLVED: 'A relative import in a compiled file could not be resolved to a source file.',
|
|
96
|
+
CMP_IMPORT_FORM: 'An import = require(...) (or import = Some.Name) declaration sits in a file that contributes classes to the generated module; the generated module is an ES module and cannot carry that form, so the declaration was dropped. Write the import as an ES module import instead.',
|
|
97
|
+
CMP_PATH_ESCAPE: 'A templateUrl, styleUrl or relative import resolved to a file outside the project root; the file was not read.',
|
|
98
|
+
CMP_IMPORT_CYCLE: 'Two or more source files import each other in a cycle; the cycle was broken at the repeated file, whose classes were already registered.',
|
|
99
|
+
CMP_DUP_SELECTOR: 'Two different component classes declare the same selector in one compilation.',
|
|
100
|
+
DI_UNKNOWN_TOKEN: 'A constructor dependency names a type that is not a known @Injectable({ providedIn: \'root\' }) service in this compilation and not a built-in token (HttpClient, Router / ActivatedRoute in a routed app, or SnackBar in a component).',
|
|
101
|
+
DI_CYCLE: 'Injectable services depend on each other in a cycle; container registrations could not be ordered.',
|
|
102
|
+
DOC_HEX_COLOR: 'Doctor: a hex colour literal appears in the component styles instead of a colour role token.',
|
|
103
|
+
DOC_OFF_SCALE: 'Doctor: a spacing, radius or font-size value in the styles is off its design-token scale (the compiler would snap it).',
|
|
104
|
+
DOC_RAW_TEXT: 'Doctor: loose text sits directly inside a container element instead of a text element.',
|
|
105
|
+
DOC_TAP_TARGET: 'Doctor: an element with a (click) binding is sized below the 44 by 44 minimum tap target.',
|
|
106
|
+
DOC_IMG_SIZE: 'Doctor: an image element has no declared width and height.',
|
|
107
|
+
CLI_INIT_NOT_EMPTY: 'The rg init command was pointed at a directory that is not empty.',
|
|
108
|
+
PIPE_UNKNOWN: 'A template uses a pipe that is neither a built-in pipe nor a @Pipe class resolved in this compilation; the JSON form lists the known pipes in the fix.',
|
|
109
|
+
GEN_VALIDATOR_ARG: 'A static minlength or maxlength attribute value is not a plain number; the validator was dropped instead of emitting the text into generated code.',
|
|
110
|
+
DIR_UNSUPPORTED: 'An attribute directive is outside the supported subset (a bracket selector, @Input fields, an ElementRef, and ngOnInit or setter bodies made only of this.el.nativeElement.style.<prop> assignments), or it is used on a host the subset cannot style; the directive applied no styles.',
|
|
111
|
+
PROJECTION_SELECT_UNSUPPORTED: 'An <ng-content> carries a select attribute; multi-slot projection is not supported yet, so the element behaves as the default slot and receives all projected children.',
|
|
112
|
+
CLI_INIT_UNSAFE: 'The rg init target name is not a safe directory name (letters, digits, dot, underscore and hyphen only, and not . or ..); nothing was written.',
|
|
113
|
+
};
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ALLOW_HEX_MARKER = void 0;
|
|
4
|
+
exports.doctorStyleTexts = doctorStyleTexts;
|
|
5
|
+
exports.runDoctor = runDoctor;
|
|
6
|
+
const compile_1 = require("./compile");
|
|
7
|
+
const generate_1 = require("./codegen/generate");
|
|
8
|
+
const diagnostics_1 = require("./diagnostics");
|
|
9
|
+
const css_1 = require("./style/css");
|
|
10
|
+
const CONTAINER_TAGS = new Set(['screen', 'card', 'list', 'sheet', 'dialog', 'tab', 'panel']);
|
|
11
|
+
const HEX_RE = /#[0-9a-fA-F]{3,8}\b/g;
|
|
12
|
+
const DECL_RE = /([a-zA-Z-]+)\s*:\s*(-?\d+(?:\.\d+)?)px/g;
|
|
13
|
+
exports.ALLOW_HEX_MARKER = 'doctor: allow-hex';
|
|
14
|
+
function lineAt(text, index) {
|
|
15
|
+
let line = 1;
|
|
16
|
+
for (let i = 0; i < index; i++)
|
|
17
|
+
if (text[i] === '\n')
|
|
18
|
+
line++;
|
|
19
|
+
return line;
|
|
20
|
+
}
|
|
21
|
+
function camelCase(prop) {
|
|
22
|
+
return prop.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
23
|
+
}
|
|
24
|
+
/** Style texts for a compilation: inline styles live in the .ts file. */
|
|
25
|
+
function doctorStyleTexts(result, entryFile, readFile) {
|
|
26
|
+
const texts = [];
|
|
27
|
+
const component = result.component;
|
|
28
|
+
if (!component)
|
|
29
|
+
return texts;
|
|
30
|
+
if (component.styles)
|
|
31
|
+
texts.push({ file: entryFile, text: component.styles });
|
|
32
|
+
for (const url of component.styleUrls) {
|
|
33
|
+
const file = (0, compile_1.resolveSiblingPath)(entryFile, url);
|
|
34
|
+
const text = readFile(file);
|
|
35
|
+
if (text !== undefined)
|
|
36
|
+
texts.push({ file, text });
|
|
37
|
+
}
|
|
38
|
+
return texts;
|
|
39
|
+
}
|
|
40
|
+
function runDoctor(input) {
|
|
41
|
+
const { result, entryFile } = input;
|
|
42
|
+
const findings = [];
|
|
43
|
+
const component = result.component;
|
|
44
|
+
if (!component || !result.ast)
|
|
45
|
+
return findings;
|
|
46
|
+
const entryTemplateFile = component.templateUrl
|
|
47
|
+
? (0, compile_1.resolveSiblingPath)(entryFile, component.templateUrl)
|
|
48
|
+
: entryFile;
|
|
49
|
+
// --- Style text checks: DOC_HEX_COLOR + DOC_OFF_SCALE --------------------
|
|
50
|
+
for (const { file, text } of input.styleTexts) {
|
|
51
|
+
const allowHex = text.includes(exports.ALLOW_HEX_MARKER);
|
|
52
|
+
if (!allowHex) {
|
|
53
|
+
for (const m of text.matchAll(HEX_RE)) {
|
|
54
|
+
findings.push({
|
|
55
|
+
...(0, diagnostics_1.warning)('DOC_HEX_COLOR', `Hex colour ${m[0]} in styles; raw hex values do not follow the theme`, lineAt(text, m.index ?? 0), undefined, `Use a colour role instead (primary, surface, onSurface, error, and the other roles in @rangular-framework/ui tokens), or, for a deliberate brand colour, add a CSS comment containing "${exports.ALLOW_HEX_MARKER}" to this style text`),
|
|
56
|
+
file,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
for (const m of text.matchAll(DECL_RE)) {
|
|
61
|
+
const rawProp = m[1];
|
|
62
|
+
const value = Number(m[2]);
|
|
63
|
+
const snapped = (0, css_1.snapForProp)(camelCase(rawProp), value);
|
|
64
|
+
if (snapped !== undefined && snapped !== value) {
|
|
65
|
+
findings.push({
|
|
66
|
+
...(0, diagnostics_1.warning)('DOC_OFF_SCALE', `${rawProp}: ${value}px is off its design-token scale; the compiler snaps it to ${snapped}`, lineAt(text, m.index ?? 0), undefined, `Change ${rawProp} to ${snapped}px so the source says what the generated style will be`),
|
|
67
|
+
file,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// --- Template checks -------------------------------------------------------
|
|
73
|
+
const styleFor = (el, styles) => {
|
|
74
|
+
const merged = { ...(styles[el.tag] ?? {}) };
|
|
75
|
+
for (const cls of (el.attrs['class'] ?? '').split(/\s+/).filter(Boolean)) {
|
|
76
|
+
Object.assign(merged, styles[cls] ?? {});
|
|
77
|
+
}
|
|
78
|
+
return merged;
|
|
79
|
+
};
|
|
80
|
+
const walk = (nodes, templateFile, styles) => {
|
|
81
|
+
for (const node of nodes) {
|
|
82
|
+
if (node.type !== 'element')
|
|
83
|
+
continue;
|
|
84
|
+
const el = node;
|
|
85
|
+
// DOC_RAW_TEXT: loose text directly inside a container.
|
|
86
|
+
if (CONTAINER_TAGS.has(el.tag)) {
|
|
87
|
+
for (const child of el.children) {
|
|
88
|
+
if (child.type !== 'text')
|
|
89
|
+
continue;
|
|
90
|
+
const loose = child.parts.some((p) => (p.type === 'static' && p.value.trim() !== '') || p.type === 'expr');
|
|
91
|
+
if (loose) {
|
|
92
|
+
findings.push({
|
|
93
|
+
...(0, diagnostics_1.warning)('DOC_RAW_TEXT', `Loose text sits directly inside <${el.tag}>; on React Native all text must live inside a text element`, child.pos.line, child.pos.column, `Wrap the text in <p>, <span>, <h1> to <h3> or <label> (whichever fits) instead of placing it directly inside <${el.tag}>`),
|
|
94
|
+
file: templateFile,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// DOC_TAP_TARGET: a (click) element sized below 44 in either dimension.
|
|
100
|
+
if (el.eventBindings.some((ev) => ev.name === 'click')) {
|
|
101
|
+
const style = styleFor(el, styles);
|
|
102
|
+
const width = typeof style.width === 'number' ? style.width : undefined;
|
|
103
|
+
const height = typeof style.height === 'number' ? style.height : undefined;
|
|
104
|
+
const attrWidth = el.attrs['width'] !== undefined ? Number(el.attrs['width']) : undefined;
|
|
105
|
+
const attrHeight = el.attrs['height'] !== undefined ? Number(el.attrs['height']) : undefined;
|
|
106
|
+
const w = width ?? (Number.isFinite(attrWidth) ? attrWidth : undefined);
|
|
107
|
+
const h = height ?? (Number.isFinite(attrHeight) ? attrHeight : undefined);
|
|
108
|
+
if ((w !== undefined && w < 44) || (h !== undefined && h < 44)) {
|
|
109
|
+
findings.push({
|
|
110
|
+
...(0, diagnostics_1.error)('DOC_TAP_TARGET', `<${el.tag}> has a (click) binding but is sized ${w !== undefined ? `${w}` : '?'} by ${h !== undefined ? `${h}` : '?'}; below the 44 by 44 minimum tap target`, el.pos.line, el.pos.column, 'Give the element width and height of at least 44 (44px or more in its styles) so the tap target is comfortably tappable'),
|
|
111
|
+
file: templateFile,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
walk(el.children, templateFile, styles);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
walk(result.ast.children, entryTemplateFile, result.css?.styles ?? {});
|
|
119
|
+
for (const child of result.children) {
|
|
120
|
+
walk(child.ast.children, child.templateFile ?? entryFile, child.css.styles);
|
|
121
|
+
}
|
|
122
|
+
// DOC_IMG_SIZE: only when an image tag is part of the tag contract.
|
|
123
|
+
// Stage 15 added <image> to TAG_MAP, so this check is live: an
|
|
124
|
+
// <image> must declare width and height so the layout does not
|
|
125
|
+
// jump when the picture lands.
|
|
126
|
+
const imageTags = ['img', 'image'].filter((t) => t in generate_1.TAG_MAP);
|
|
127
|
+
if (imageTags.length) {
|
|
128
|
+
const checkImages = (nodes, templateFile) => {
|
|
129
|
+
for (const node of nodes) {
|
|
130
|
+
if (node.type !== 'element')
|
|
131
|
+
continue;
|
|
132
|
+
if (imageTags.includes(node.tag) && (!node.attrs['width'] || !node.attrs['height'])) {
|
|
133
|
+
findings.push({
|
|
134
|
+
...(0, diagnostics_1.error)('DOC_IMG_SIZE', `<${node.tag}> has no declared width and height; images must declare their size so layout does not jump`, node.pos.line, node.pos.column, 'Add width and height attributes with the image size in px, e.g. width="120" height="80"'),
|
|
135
|
+
file: templateFile,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
checkImages(node.children, templateFile);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
checkImages(result.ast.children, entryTemplateFile);
|
|
142
|
+
}
|
|
143
|
+
return findings;
|
|
144
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fixStyleText = fixStyleText;
|
|
4
|
+
const css_1 = require("./style/css");
|
|
5
|
+
function camelCase(prop) {
|
|
6
|
+
return prop.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Rewrite one style text: off-scale numeric values are written back
|
|
10
|
+
* at their snapped value (the same snap the compiler would apply,
|
|
11
|
+
* via snapForProp), and unsupported properties are removed with a
|
|
12
|
+
* comment naming what was taken out and why.
|
|
13
|
+
*/
|
|
14
|
+
function fixStyleText(text) {
|
|
15
|
+
const fixes = [];
|
|
16
|
+
const out = text.replace(/([^{}]+)\{([^{}]*)\}/g, (whole, selector, body) => {
|
|
17
|
+
const decls = body.split(';').map((decl) => {
|
|
18
|
+
const m = /^(\s*)([a-zA-Z-]+)(\s*:\s*)(-?\d+(?:\.\d+)?)(px)?(\s*)$/.exec(decl);
|
|
19
|
+
if (!m) {
|
|
20
|
+
const bare = /^(\s*)([a-zA-Z-]+)\s*:/.exec(decl);
|
|
21
|
+
if (bare && !css_1.SUPPORTED_STYLE_PROPERTIES.has(camelCase(bare[2]))) {
|
|
22
|
+
fixes.push({ code: 'CSS_UNSUPPORTED', detail: `removed '${bare[2]}' from '${selector.trim()}'` });
|
|
23
|
+
return `${bare[1]}/* rg fix: removed '${bare[2]}' (CSS_UNSUPPORTED: not a supported property) */`;
|
|
24
|
+
}
|
|
25
|
+
return decl;
|
|
26
|
+
}
|
|
27
|
+
const [, lead, rawProp, mid, numText, px, tail] = m;
|
|
28
|
+
const prop = camelCase(rawProp);
|
|
29
|
+
if (!css_1.SUPPORTED_STYLE_PROPERTIES.has(prop)) {
|
|
30
|
+
fixes.push({ code: 'CSS_UNSUPPORTED', detail: `removed '${rawProp}' from '${selector.trim()}'` });
|
|
31
|
+
return `${lead}/* rg fix: removed '${rawProp}' (CSS_UNSUPPORTED: not a supported property) */${tail}`;
|
|
32
|
+
}
|
|
33
|
+
const value = Number(numText);
|
|
34
|
+
const snapped = (0, css_1.snapForProp)(prop, value);
|
|
35
|
+
if (snapped !== undefined && snapped !== value) {
|
|
36
|
+
fixes.push({ code: 'STYLE_OFF_SCALE', detail: `'${selector.trim()}' ${rawProp}: ${value} -> ${snapped}` });
|
|
37
|
+
return `${lead}${rawProp}${mid}${snapped}${px ?? ''}${tail}`;
|
|
38
|
+
}
|
|
39
|
+
return decl;
|
|
40
|
+
});
|
|
41
|
+
return `${selector}{${decls.join(';')}}`;
|
|
42
|
+
});
|
|
43
|
+
return { text: out, fixes };
|
|
44
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
__exportStar(require("./diagnostics"), exports);
|
|
18
|
+
__exportStar(require("./template/ast"), exports);
|
|
19
|
+
__exportStar(require("./template/parser"), exports);
|
|
20
|
+
__exportStar(require("./template/printAst"), exports);
|
|
21
|
+
__exportStar(require("./template/expr"), exports);
|
|
22
|
+
__exportStar(require("./template/evaluate"), exports);
|
|
23
|
+
__exportStar(require("./template/pipes"), exports);
|
|
24
|
+
__exportStar(require("./template/literal"), exports);
|
|
25
|
+
__exportStar(require("./template/structural"), exports);
|
|
26
|
+
__exportStar(require("./class/parseComponent"), exports);
|
|
27
|
+
__exportStar(require("./class/parseDirective"), exports);
|
|
28
|
+
__exportStar(require("./class/parseRoutes"), exports);
|
|
29
|
+
__exportStar(require("./style/css"), exports);
|
|
30
|
+
__exportStar(require("./codegen/generate"), exports);
|
|
31
|
+
__exportStar(require("./codegen/methods"), exports);
|
|
32
|
+
__exportStar(require("./preview/renderPreview"), exports);
|
|
33
|
+
__exportStar(require("./preview/styleSnapshot"), exports);
|
|
34
|
+
__exportStar(require("./codegen/sourceMap"), exports);
|
|
35
|
+
__exportStar(require("./doctor"), exports);
|
|
36
|
+
__exportStar(require("./compile"), exports);
|
|
37
|
+
__exportStar(require("./catalog"), exports);
|
|
38
|
+
__exportStar(require("./fix"), exports);
|