render-core 1.4.16 → 1.4.20
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/LICENSE +21 -0
- package/README.md +2 -0
- package/index.js +11 -1
- package/kernel/delivery/delivery.d.ts +0 -1
- package/kernel/delivery/delivery.js +0 -1
- package/lint/directive-linter.d.ts +16 -0
- package/lint/directive-linter.js +123 -0
- package/package.json +4 -1
- package/system/lifecycle/mount.js +1 -1
- package/system/output/errorUtility.d.ts +4 -3
- package/system/output/errorUtility.js +2 -2
- package/tension/SystemInitPlugin.d.ts +3 -0
- package/tension/SystemInitPlugin.js +3 -0
- package/verify/directive-linter.d.ts +4 -0
- package/verify/directive-linter.js +123 -0
- package/verify/generic/lintError.d.ts +6 -0
- package/verify/generic/lintError.js +1 -0
- package/verify/generic/location.d.ts +7 -0
- package/verify/generic/location.js +1 -0
- package/xboot/tagProcessor.d.ts +1 -1
- package/xboot/tagProcessor.js +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 render-js
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/index.js
CHANGED
|
@@ -21,6 +21,8 @@ import { AbstractComponent } from "./tension/prototype/AbstractComponent";
|
|
|
21
21
|
import { set_context_controller } from "./system/recorder/table0/system_func_0";
|
|
22
22
|
import { PrefaceAction } from "./tension/prototype/PrefaceAction";
|
|
23
23
|
import { SystemInitPlugin } from "./tension/SystemInitPlugin";
|
|
24
|
+
import { lintComponent } from "./verify/directive-linter";
|
|
25
|
+
import { errorDisplay } from "./system/output/errorUtility";
|
|
24
26
|
/**
|
|
25
27
|
* This class is used to prototype the properties type
|
|
26
28
|
*/
|
|
@@ -95,7 +97,15 @@ var RenderJS = /** @class */ (function () {
|
|
|
95
97
|
* @param component
|
|
96
98
|
*/
|
|
97
99
|
RenderJS.prototype.add_tag = function (component) {
|
|
98
|
-
|
|
100
|
+
var errors = lintComponent(component);
|
|
101
|
+
if (errors.length > 0) {
|
|
102
|
+
errors.map(function (error) {
|
|
103
|
+
errorDisplay(component.getName(), error);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
registerTagLib(component);
|
|
108
|
+
}
|
|
99
109
|
};
|
|
100
110
|
/**
|
|
101
111
|
* This func is used to work under the route mode
|
|
@@ -6,7 +6,6 @@ import { raw_renderer } from "../renderer/rawRender";
|
|
|
6
6
|
import { renderHtml } from "../../xboot/renderProcessor";
|
|
7
7
|
import { tag_unknown_check } from "../../system/recorder/table2/system_func_2";
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
10
9
|
* @param protoTypeComponent
|
|
11
10
|
* @param componentAttachedRootElement
|
|
12
11
|
* @param child
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Component } from "../index";
|
|
2
|
+
export interface DirectiveLocation {
|
|
3
|
+
directive: string;
|
|
4
|
+
expression: string;
|
|
5
|
+
element: string;
|
|
6
|
+
line: number;
|
|
7
|
+
column: number;
|
|
8
|
+
}
|
|
9
|
+
export interface LintError {
|
|
10
|
+
rule: string;
|
|
11
|
+
message: string;
|
|
12
|
+
line: number;
|
|
13
|
+
column: number;
|
|
14
|
+
}
|
|
15
|
+
export declare function lintComponent(component: Component): LintError[];
|
|
16
|
+
export declare function lintComponents(components: Component[]): Map<string, LintError[]>;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
var BOOLEAN_CONDITION_DIRECTIVES = ["@if", "@show"];
|
|
2
|
+
var ARRAY_ITERATION_DIRECTIVES = ["@for", "@map"];
|
|
3
|
+
var MODEL_ELEMENT = ["INPUT", "SELECT", "TEXTAREA"];
|
|
4
|
+
function parseTemplateForDirectives(template) {
|
|
5
|
+
var directives = [];
|
|
6
|
+
var lines = template.split("\n");
|
|
7
|
+
for (var lineIndex = 0; lineIndex < lines.length; lineIndex++) {
|
|
8
|
+
var line = lines[lineIndex];
|
|
9
|
+
var directiveRegex = /@(\w+)(?:\s*=\s*"([^"]*)"|\s*=\s*'([^']*)')?/g;
|
|
10
|
+
var match = void 0;
|
|
11
|
+
while ((match = directiveRegex.exec(line)) !== null) {
|
|
12
|
+
var directiveName = match[1];
|
|
13
|
+
var expression = match[2] || match[3] || "";
|
|
14
|
+
var elementMatch = line.match(/<(\w+)/);
|
|
15
|
+
var element = elementMatch ? elementMatch[1] : "unknown";
|
|
16
|
+
directives.push({
|
|
17
|
+
directive: "@".concat(directiveName),
|
|
18
|
+
expression: expression,
|
|
19
|
+
element: element.toUpperCase(),
|
|
20
|
+
line: lineIndex + 1,
|
|
21
|
+
column: match.index + 1
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return directives;
|
|
26
|
+
}
|
|
27
|
+
function inferType(value) {
|
|
28
|
+
if (value === true || value === false)
|
|
29
|
+
return "boolean";
|
|
30
|
+
if (Array.isArray(value))
|
|
31
|
+
return "array";
|
|
32
|
+
if (typeof value === "number")
|
|
33
|
+
return "number";
|
|
34
|
+
if (typeof value === "string")
|
|
35
|
+
return "string";
|
|
36
|
+
if (typeof value === "object" && value !== null)
|
|
37
|
+
return "object";
|
|
38
|
+
if (value === null)
|
|
39
|
+
return "null";
|
|
40
|
+
return "unknown";
|
|
41
|
+
}
|
|
42
|
+
function getDataTypes(component) {
|
|
43
|
+
var types = new Map();
|
|
44
|
+
var data = component.getData();
|
|
45
|
+
if (data && typeof data === "object") {
|
|
46
|
+
Object.keys(data).forEach(function (key) {
|
|
47
|
+
types.set(key, inferType(data[key]));
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return types;
|
|
51
|
+
}
|
|
52
|
+
function validateBooleanCondition(directive, component) {
|
|
53
|
+
var dataTypes = getDataTypes(component);
|
|
54
|
+
var actualType = dataTypes.get(directive.expression);
|
|
55
|
+
if (actualType && actualType !== "boolean") {
|
|
56
|
+
return {
|
|
57
|
+
rule: "boolean-condition",
|
|
58
|
+
message: "Directive '".concat(directive.directive, "' expects boolean but '").concat(directive.expression, "' is ").concat(actualType),
|
|
59
|
+
line: directive.line,
|
|
60
|
+
column: directive.column
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
function validateArrayIteration(directive, component) {
|
|
66
|
+
var dataTypes = getDataTypes(component);
|
|
67
|
+
var actualType = dataTypes.get(directive.expression);
|
|
68
|
+
if (actualType && actualType !== "array") {
|
|
69
|
+
return {
|
|
70
|
+
rule: "array-iteration",
|
|
71
|
+
message: "Directive '".concat(directive.directive, "' expects array but '").concat(directive.expression, "' is ").concat(actualType),
|
|
72
|
+
line: directive.line,
|
|
73
|
+
column: directive.column
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
function validateModelElement(directive, component) {
|
|
79
|
+
if (MODEL_ELEMENT.indexOf(directive.element) === -1) {
|
|
80
|
+
return {
|
|
81
|
+
rule: "valid-model-element",
|
|
82
|
+
message: "Directive '@model' can only be used on INPUT, SELECT, or TEXTAREA, but found '".concat(directive.element, "'"),
|
|
83
|
+
line: directive.line,
|
|
84
|
+
column: directive.column
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
export function lintComponent(component) {
|
|
90
|
+
var errors = [];
|
|
91
|
+
var template = component.getTemplate();
|
|
92
|
+
var directives = parseTemplateForDirectives(template);
|
|
93
|
+
for (var _i = 0, directives_1 = directives; _i < directives_1.length; _i++) {
|
|
94
|
+
var directive = directives_1[_i];
|
|
95
|
+
if (BOOLEAN_CONDITION_DIRECTIVES.indexOf(directive.directive) !== -1) {
|
|
96
|
+
var error = validateBooleanCondition(directive, component);
|
|
97
|
+
if (error)
|
|
98
|
+
errors.push(error);
|
|
99
|
+
}
|
|
100
|
+
if (ARRAY_ITERATION_DIRECTIVES.indexOf(directive.directive) !== -1) {
|
|
101
|
+
var error = validateArrayIteration(directive, component);
|
|
102
|
+
if (error)
|
|
103
|
+
errors.push(error);
|
|
104
|
+
}
|
|
105
|
+
if (directive.directive === "@model") {
|
|
106
|
+
var error = validateModelElement(directive, component);
|
|
107
|
+
if (error)
|
|
108
|
+
errors.push(error);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return errors;
|
|
112
|
+
}
|
|
113
|
+
export function lintComponents(components) {
|
|
114
|
+
var allErrors = new Map();
|
|
115
|
+
for (var _i = 0, components_1 = components; _i < components_1.length; _i++) {
|
|
116
|
+
var component = components_1[_i];
|
|
117
|
+
var errors = lintComponent(component);
|
|
118
|
+
if (errors.length > 0) {
|
|
119
|
+
allErrors.set(component.getName(), errors);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return allErrors;
|
|
123
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "render-core",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.20",
|
|
4
4
|
"description": "The extendable javascript web framework",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc"
|
|
9
|
+
},
|
|
7
10
|
"repository": {
|
|
8
11
|
"type": "git",
|
|
9
12
|
"url": "https://github.com//render-js/render-core.git"
|
|
@@ -34,7 +34,7 @@ export function extract_mount(root) {
|
|
|
34
34
|
// @ts-ignore
|
|
35
35
|
root.anchorEnd = root.componentAttachedRootElement;
|
|
36
36
|
root.anchorEnd.setAttribute("anchor", "end");
|
|
37
|
-
root.
|
|
37
|
+
root.anchorBegin.setAttribute("style", "display:none");
|
|
38
38
|
root.componentAttachedRootElement = parent;
|
|
39
39
|
}
|
|
40
40
|
export function mountForUpdate(tagTemplate) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function
|
|
1
|
+
import LintError from "../../verify/generic/lintError";
|
|
2
|
+
export declare function errorDisplay(tag: string, error: LintError): void;
|
|
3
|
+
export declare function warnDisplay(error: LintError): void;
|
|
4
|
+
export declare function infoDisplay(error: LintError): void;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { PrefaceGeneric } from "./generic/plugin/preface/PrefaceGeneric";
|
|
2
2
|
import { HooksGeneric } from "./generic/plugin/hooks/HooksGeneric";
|
|
3
3
|
import { PluginGeneric } from "./generic/plugin/PluginGeneric";
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
4
7
|
export declare class SystemInitPlugin implements PluginGeneric {
|
|
5
8
|
plugin(preface: PrefaceGeneric, hooks: HooksGeneric): void;
|
|
6
9
|
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
var BOOLEAN_CONDITION_DIRECTIVES = ["@if", "@show"];
|
|
2
|
+
var ARRAY_ITERATION_DIRECTIVES = ["@for", "@map"];
|
|
3
|
+
var MODEL_ELEMENT = ["INPUT", "SELECT", "TEXTAREA"];
|
|
4
|
+
function parseTemplateForDirectives(template) {
|
|
5
|
+
var directives = [];
|
|
6
|
+
var lines = template.split("\n");
|
|
7
|
+
for (var lineIndex = 0; lineIndex < lines.length; lineIndex++) {
|
|
8
|
+
var line = lines[lineIndex];
|
|
9
|
+
var directiveRegex = /@(\w+)(?:\s*=\s*"([^"]*)"|\s*=\s*'([^']*)')?/g;
|
|
10
|
+
var match = void 0;
|
|
11
|
+
while ((match = directiveRegex.exec(line)) !== null) {
|
|
12
|
+
var directiveName = match[1];
|
|
13
|
+
var expression = match[2] || match[3] || "";
|
|
14
|
+
var elementMatch = line.match(/<(\w+)/);
|
|
15
|
+
var element = elementMatch ? elementMatch[1] : "unknown";
|
|
16
|
+
directives.push({
|
|
17
|
+
directive: "@".concat(directiveName),
|
|
18
|
+
expression: expression,
|
|
19
|
+
element: element.toUpperCase(),
|
|
20
|
+
line: lineIndex + 1,
|
|
21
|
+
column: match.index + 1
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return directives;
|
|
26
|
+
}
|
|
27
|
+
function inferType(value) {
|
|
28
|
+
if (value === true || value === false)
|
|
29
|
+
return "boolean";
|
|
30
|
+
if (Array.isArray(value))
|
|
31
|
+
return "array";
|
|
32
|
+
if (typeof value === "number")
|
|
33
|
+
return "number";
|
|
34
|
+
if (typeof value === "string")
|
|
35
|
+
return "string";
|
|
36
|
+
if (typeof value === "object" && value !== null)
|
|
37
|
+
return "object";
|
|
38
|
+
if (value === null)
|
|
39
|
+
return "null";
|
|
40
|
+
return "unknown";
|
|
41
|
+
}
|
|
42
|
+
function getDataTypes(component) {
|
|
43
|
+
var types = new Map();
|
|
44
|
+
var data = component.getData();
|
|
45
|
+
if (data && typeof data === "object") {
|
|
46
|
+
Object.keys(data).forEach(function (key) {
|
|
47
|
+
types.set(key, inferType(data[key]));
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return types;
|
|
51
|
+
}
|
|
52
|
+
function validateBooleanCondition(directive, component) {
|
|
53
|
+
var dataTypes = getDataTypes(component);
|
|
54
|
+
var actualType = dataTypes.get(directive.expression);
|
|
55
|
+
if (actualType && actualType !== "boolean") {
|
|
56
|
+
return {
|
|
57
|
+
rule: "boolean-condition",
|
|
58
|
+
message: "Directive '".concat(directive.directive, "' expects boolean but '").concat(directive.expression, "' is ").concat(actualType),
|
|
59
|
+
line: directive.line,
|
|
60
|
+
column: directive.column
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
function validateArrayIteration(directive, component) {
|
|
66
|
+
var dataTypes = getDataTypes(component);
|
|
67
|
+
var actualType = dataTypes.get(directive.expression);
|
|
68
|
+
if (actualType && actualType !== "array") {
|
|
69
|
+
return {
|
|
70
|
+
rule: "array-iteration",
|
|
71
|
+
message: "Directive '".concat(directive.directive, "' expects array but '").concat(directive.expression, "' is ").concat(actualType),
|
|
72
|
+
line: directive.line,
|
|
73
|
+
column: directive.column
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
function validateModelElement(directive, component) {
|
|
79
|
+
if (MODEL_ELEMENT.indexOf(directive.element) === -1) {
|
|
80
|
+
return {
|
|
81
|
+
rule: "valid-model-element",
|
|
82
|
+
message: "Directive '@model' can only be used on INPUT, SELECT, or TEXTAREA, but found '".concat(directive.element, "'"),
|
|
83
|
+
line: directive.line,
|
|
84
|
+
column: directive.column
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
export function lintComponent(component) {
|
|
90
|
+
var errors = [];
|
|
91
|
+
var template = component.getTemplate();
|
|
92
|
+
var directives = parseTemplateForDirectives(template);
|
|
93
|
+
for (var _i = 0, directives_1 = directives; _i < directives_1.length; _i++) {
|
|
94
|
+
var directive = directives_1[_i];
|
|
95
|
+
if (BOOLEAN_CONDITION_DIRECTIVES.indexOf(directive.directive) !== -1) {
|
|
96
|
+
var error = validateBooleanCondition(directive, component);
|
|
97
|
+
if (error)
|
|
98
|
+
errors.push(error);
|
|
99
|
+
}
|
|
100
|
+
if (ARRAY_ITERATION_DIRECTIVES.indexOf(directive.directive) !== -1) {
|
|
101
|
+
var error = validateArrayIteration(directive, component);
|
|
102
|
+
if (error)
|
|
103
|
+
errors.push(error);
|
|
104
|
+
}
|
|
105
|
+
if (directive.directive === "@model") {
|
|
106
|
+
var error = validateModelElement(directive, component);
|
|
107
|
+
if (error)
|
|
108
|
+
errors.push(error);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return errors;
|
|
112
|
+
}
|
|
113
|
+
export function lintComponents(components) {
|
|
114
|
+
var allErrors = new Map();
|
|
115
|
+
for (var _i = 0, components_1 = components; _i < components_1.length; _i++) {
|
|
116
|
+
var component = components_1[_i];
|
|
117
|
+
var errors = lintComponent(component);
|
|
118
|
+
if (errors.length > 0) {
|
|
119
|
+
allErrors.set(component.getName(), errors);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return allErrors;
|
|
123
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/xboot/tagProcessor.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Component } from "../index";
|
|
2
2
|
/**
|
|
3
3
|
* This function is used to save the prototype component proto in the window object.
|
|
4
|
-
* So, you can
|
|
4
|
+
* So, you can have a tip that we custom a property named 'tagLib' in the window object.
|
|
5
5
|
* @param component
|
|
6
6
|
*/
|
|
7
7
|
export declare function registerTagLib(component: Component | Component[]): void;
|
package/xboot/tagProcessor.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { get_tag_library } from "../system/recorder/table0/system_func_0";
|
|
2
2
|
/**
|
|
3
3
|
* This function is used to save the prototype component proto in the window object.
|
|
4
|
-
* So, you can
|
|
4
|
+
* So, you can have a tip that we custom a property named 'tagLib' in the window object.
|
|
5
5
|
* @param component
|
|
6
6
|
*/
|
|
7
7
|
export function registerTagLib(component) {
|