edgexpress 3.0.1 → 3.0.2
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/eslint.config.cjs +6 -0
- package/examples/index.js +41 -0
- package/examples/views/components/layout/main.edge +26 -0
- package/examples/views/components/modal.edge +27 -0
- package/examples/views/home.edge +84 -0
- package/examples/views/partials/button.edge +1 -0
- package/examples/views/partials/home-footer.edge +49 -0
- package/examples/views/partials/home-header.edge +61 -0
- package/examples/views/welcome.edge +22 -0
- package/index.d.ts +7 -0
- package/package.json +3 -3
- package/src/cache_manager.d.ts +28 -0
- package/src/cache_manager.js +58 -0
- package/src/compiler.d.ts +73 -0
- package/src/compiler.js +319 -0
- package/src/component/props.d.ts +53 -0
- package/src/component/props.js +110 -0
- package/src/edge/globals.d.ts +5 -0
- package/src/edge/globals.js +95 -0
- package/src/edge/main.d.ts +192 -0
- package/src/edge/main.js +334 -0
- package/src/edge/renderer.d.ts +44 -0
- package/src/edge/renderer.js +85 -0
- package/src/edge/stacks.d.ts +22 -0
- package/src/edge/stacks.js +98 -0
- package/src/loader.d.ts +138 -0
- package/src/loader.js +347 -0
- package/src/migrate/globals.d.ts +1 -0
- package/src/migrate/globals.js +100 -0
- package/src/migrate/plugin.d.ts +2 -0
- package/src/migrate/plugin.js +58 -0
- package/src/migrate/props.d.ts +66 -0
- package/src/migrate/props.js +129 -0
- package/src/migrate/tags/layout.d.ts +6 -0
- package/src/migrate/tags/layout.js +25 -0
- package/src/migrate/tags/main.d.ts +4 -0
- package/src/migrate/tags/main.js +19 -0
- package/src/migrate/tags/section.d.ts +6 -0
- package/src/migrate/tags/section.js +23 -0
- package/src/migrate/tags/set.d.ts +26 -0
- package/src/migrate/tags/set.js +104 -0
- package/src/migrate/tags/super.d.ts +9 -0
- package/src/migrate/tags/super.js +31 -0
- package/src/plugins/supercharged.d.ts +4 -0
- package/src/plugins/supercharged.js +88 -0
- package/src/processor.d.ts +42 -0
- package/src/processor.js +86 -0
- package/src/tags/assign.d.ts +5 -0
- package/src/tags/assign.js +42 -0
- package/src/tags/component.d.ts +6 -0
- package/src/tags/component.js +299 -0
- package/src/tags/debugger.d.ts +5 -0
- package/src/tags/debugger.js +26 -0
- package/src/tags/each.d.ts +20 -0
- package/src/tags/each.js +185 -0
- package/src/tags/else.d.ts +2 -0
- package/src/tags/else.js +22 -0
- package/src/tags/else_if.d.ts +7 -0
- package/src/tags/else_if.js +39 -0
- package/src/tags/eval.d.ts +7 -0
- package/src/tags/eval.js +30 -0
- package/src/tags/if.d.ts +5 -0
- package/src/tags/if.js +45 -0
- package/src/tags/include.d.ts +27 -0
- package/src/tags/include.js +78 -0
- package/src/tags/include_if.d.ts +10 -0
- package/src/tags/include_if.js +61 -0
- package/src/tags/inject.d.ts +6 -0
- package/src/tags/inject.js +40 -0
- package/src/tags/let.d.ts +6 -0
- package/src/tags/let.js +69 -0
- package/src/tags/main.d.ts +18 -0
- package/src/tags/main.js +47 -0
- package/src/tags/new_error.d.ts +6 -0
- package/src/tags/new_error.js +47 -0
- package/src/tags/push_once_to.d.ts +13 -0
- package/src/tags/push_once_to.js +65 -0
- package/src/tags/push_to.d.ts +7 -0
- package/src/tags/push_to.js +62 -0
- package/src/tags/slot.d.ts +6 -0
- package/src/tags/slot.js +29 -0
- package/src/tags/stack.d.ts +5 -0
- package/src/tags/stack.js +38 -0
- package/src/tags/unless.d.ts +12 -0
- package/src/tags/unless.js +52 -0
- package/src/template.d.ts +127 -0
- package/src/template.js +203 -0
- package/src/types.d.ts +144 -0
- package/src/types.js +10 -0
- package/src/utils.d.ts +96 -0
- package/src/utils.js +297 -0
- package/tsconfig.json +16 -0
package/src/tags/else.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* edge.js
|
|
4
|
+
*
|
|
5
|
+
* (c) EdgeJS
|
|
6
|
+
*
|
|
7
|
+
* For the full copyright and license information, please view the LICENSE
|
|
8
|
+
* file that was distributed with this source code.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.elseTag = void 0;
|
|
12
|
+
exports.elseTag = {
|
|
13
|
+
block: false,
|
|
14
|
+
seekable: false,
|
|
15
|
+
tagName: 'else',
|
|
16
|
+
/**
|
|
17
|
+
* Compiles else block node to Javascript else statement
|
|
18
|
+
*/
|
|
19
|
+
compile(_, buffer, token) {
|
|
20
|
+
buffer.writeStatement('} else {', token.filename, -1);
|
|
21
|
+
},
|
|
22
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type TagContract } from '../types.js'
|
|
2
|
+
/**
|
|
3
|
+
* Else if tag is used to define conditional blocks. We keep `@elseif` tag
|
|
4
|
+
* is a inline tag, so that everything between the `if` and the `elseif`
|
|
5
|
+
* comes `if` children.
|
|
6
|
+
*/
|
|
7
|
+
export declare const elseIfTag: TagContract
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* edge.js
|
|
4
|
+
*
|
|
5
|
+
* (c) EdgeJS
|
|
6
|
+
*
|
|
7
|
+
* For the full copyright and license information, please view the LICENSE
|
|
8
|
+
* file that was distributed with this source code.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.elseIfTag = void 0;
|
|
12
|
+
const edge_parser_1 = require("edge-parser");
|
|
13
|
+
const utils_js_1 = require("../utils.js");
|
|
14
|
+
/**
|
|
15
|
+
* Else if tag is used to define conditional blocks. We keep `@elseif` tag
|
|
16
|
+
* is a inline tag, so that everything between the `if` and the `elseif`
|
|
17
|
+
* comes `if` children.
|
|
18
|
+
*/
|
|
19
|
+
exports.elseIfTag = {
|
|
20
|
+
block: false,
|
|
21
|
+
seekable: true,
|
|
22
|
+
tagName: 'elseif',
|
|
23
|
+
/**
|
|
24
|
+
* Compiles the else if block node to a Javascript if statement
|
|
25
|
+
*/
|
|
26
|
+
compile(parser, buffer, token) {
|
|
27
|
+
const parsed = (0, utils_js_1.parseJsArg)(parser, token);
|
|
28
|
+
/**
|
|
29
|
+
* Disallow sequence expressions
|
|
30
|
+
*/
|
|
31
|
+
(0, utils_js_1.isNotSubsetOf)(parsed, [edge_parser_1.expressions.SequenceExpression], () => {
|
|
32
|
+
(0, utils_js_1.unallowedExpression)(`{${token.properties.jsArg}} is not a valid argument type for the @elseif tag`, token.filename, parser.utils.getExpressionLoc(parsed));
|
|
33
|
+
});
|
|
34
|
+
/**
|
|
35
|
+
* Start else if block
|
|
36
|
+
*/
|
|
37
|
+
buffer.writeStatement(`} else if (${parser.utils.stringify(parsed)}) {`, token.filename, token.loc.start.line);
|
|
38
|
+
},
|
|
39
|
+
};
|
package/src/tags/eval.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* edge.js
|
|
4
|
+
*
|
|
5
|
+
* (c) EdgeJS
|
|
6
|
+
*
|
|
7
|
+
* For the full copyright and license information, please view the LICENSE
|
|
8
|
+
* file that was distributed with this source code.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.evalTag = void 0;
|
|
12
|
+
const utils_js_1 = require("../utils.js");
|
|
13
|
+
/**
|
|
14
|
+
* The eval tag accepts expressions similar to double curly
|
|
15
|
+
* braces. However, it does not write anything to the
|
|
16
|
+
* output.
|
|
17
|
+
*/
|
|
18
|
+
exports.evalTag = {
|
|
19
|
+
block: false,
|
|
20
|
+
seekable: true,
|
|
21
|
+
tagName: 'eval',
|
|
22
|
+
noNewLine: true,
|
|
23
|
+
/**
|
|
24
|
+
* Compiles the tag AST
|
|
25
|
+
*/
|
|
26
|
+
compile(parser, buffer, token) {
|
|
27
|
+
const parsed = (0, utils_js_1.parseJsArg)(parser, token);
|
|
28
|
+
buffer.writeExpression(parser.utils.stringify(parsed), token.filename, token.loc.start.line);
|
|
29
|
+
},
|
|
30
|
+
};
|
package/src/tags/if.d.ts
ADDED
package/src/tags/if.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* edge.js
|
|
4
|
+
*
|
|
5
|
+
* (c) EdgeJS
|
|
6
|
+
*
|
|
7
|
+
* For the full copyright and license information, please view the LICENSE
|
|
8
|
+
* file that was distributed with this source code.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.ifTag = void 0;
|
|
12
|
+
const edge_parser_1 = require("edge-parser");
|
|
13
|
+
const utils_js_1 = require("../utils.js");
|
|
14
|
+
/**
|
|
15
|
+
* If tag is used to define conditional blocks.
|
|
16
|
+
*/
|
|
17
|
+
exports.ifTag = {
|
|
18
|
+
block: true,
|
|
19
|
+
seekable: true,
|
|
20
|
+
tagName: 'if',
|
|
21
|
+
/**
|
|
22
|
+
* Compiles the if block node to a Javascript if statement
|
|
23
|
+
*/
|
|
24
|
+
compile(parser, buffer, token) {
|
|
25
|
+
const parsed = (0, utils_js_1.parseJsArg)(parser, token);
|
|
26
|
+
/**
|
|
27
|
+
* Disallow sequence expressions
|
|
28
|
+
*/
|
|
29
|
+
(0, utils_js_1.isNotSubsetOf)(parsed, [edge_parser_1.expressions.SequenceExpression], () => {
|
|
30
|
+
(0, utils_js_1.unallowedExpression)(`"${token.properties.jsArg}" is not a valid argument type for the @if tag`, token.filename, parser.utils.getExpressionLoc(parsed));
|
|
31
|
+
});
|
|
32
|
+
/**
|
|
33
|
+
* Start if block
|
|
34
|
+
*/
|
|
35
|
+
buffer.writeStatement(`if (${parser.utils.stringify(parsed)}) {`, token.filename, token.loc.start.line);
|
|
36
|
+
/**
|
|
37
|
+
* Process of all children recursively
|
|
38
|
+
*/
|
|
39
|
+
token.children.forEach((child) => parser.processToken(child, buffer));
|
|
40
|
+
/**
|
|
41
|
+
* Close if block
|
|
42
|
+
*/
|
|
43
|
+
buffer.writeStatement('}', token.filename, -1);
|
|
44
|
+
},
|
|
45
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type Parser } from 'edge-parser'
|
|
2
|
+
import type { TagContract } from '../types.js'
|
|
3
|
+
/**
|
|
4
|
+
* List of expressions allowed for the include tag
|
|
5
|
+
*/
|
|
6
|
+
export declare const ALLOWED_EXPRESSION: (
|
|
7
|
+
| 'Identifier'
|
|
8
|
+
| 'MemberExpression'
|
|
9
|
+
| 'CallExpression'
|
|
10
|
+
| 'Literal'
|
|
11
|
+
| 'TemplateLiteral'
|
|
12
|
+
| 'ConditionalExpression'
|
|
13
|
+
| 'LogicalExpression'
|
|
14
|
+
)[]
|
|
15
|
+
/**
|
|
16
|
+
* Returns the expression for rendering the partial
|
|
17
|
+
*/
|
|
18
|
+
export declare function getRenderExpression(parser: Parser, parsedExpression: any): string
|
|
19
|
+
/**
|
|
20
|
+
* Include tag is used to include partials in the same scope of the parent
|
|
21
|
+
* template.
|
|
22
|
+
*
|
|
23
|
+
* ```edge
|
|
24
|
+
* @include('partials.header')
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare const includeTag: TagContract
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* edge.js
|
|
4
|
+
*
|
|
5
|
+
* (c) AdonisJS
|
|
6
|
+
*
|
|
7
|
+
* For the full copyright and license information, please view the LICENSE
|
|
8
|
+
* file that was distributed with this source code.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.includeTag = exports.ALLOWED_EXPRESSION = void 0;
|
|
12
|
+
exports.getRenderExpression = getRenderExpression;
|
|
13
|
+
const edge_parser_1 = require("edge-parser");
|
|
14
|
+
const utils_js_1 = require("../utils.js");
|
|
15
|
+
/**
|
|
16
|
+
* List of expressions allowed for the include tag
|
|
17
|
+
*/
|
|
18
|
+
exports.ALLOWED_EXPRESSION = [
|
|
19
|
+
edge_parser_1.expressions.Literal,
|
|
20
|
+
edge_parser_1.expressions.Identifier,
|
|
21
|
+
edge_parser_1.expressions.CallExpression,
|
|
22
|
+
edge_parser_1.expressions.TemplateLiteral,
|
|
23
|
+
edge_parser_1.expressions.MemberExpression,
|
|
24
|
+
edge_parser_1.expressions.LogicalExpression,
|
|
25
|
+
edge_parser_1.expressions.ConditionalExpression,
|
|
26
|
+
];
|
|
27
|
+
/**
|
|
28
|
+
* Returns the expression for rendering the partial
|
|
29
|
+
*/
|
|
30
|
+
function getRenderExpression(parser, parsedExpression) {
|
|
31
|
+
/**
|
|
32
|
+
* We need to pass the local variables to the partial render function
|
|
33
|
+
*/
|
|
34
|
+
const localVariables = parser.stack.list();
|
|
35
|
+
/**
|
|
36
|
+
* Arguments for the `renderInline` method
|
|
37
|
+
*/
|
|
38
|
+
const renderArgs = localVariables.length
|
|
39
|
+
? [
|
|
40
|
+
parser.utils.stringify(parsedExpression),
|
|
41
|
+
localVariables.map((localVar) => `"${localVar}"`).join(','),
|
|
42
|
+
]
|
|
43
|
+
: [parser.utils.stringify(parsedExpression)];
|
|
44
|
+
/**
|
|
45
|
+
* Arguments for invoking the output function of `renderInline`
|
|
46
|
+
*/
|
|
47
|
+
const callFnArgs = localVariables.length
|
|
48
|
+
? ['template', 'state', '$context', localVariables.map((localVar) => localVar).join(',')]
|
|
49
|
+
: ['template', 'state', '$context'];
|
|
50
|
+
return `template.compilePartial(${renderArgs.join(',')})(${callFnArgs.join(',')})`;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Include tag is used to include partials in the same scope of the parent
|
|
54
|
+
* template.
|
|
55
|
+
*
|
|
56
|
+
* ```edge
|
|
57
|
+
* @include('partials.header')
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
exports.includeTag = {
|
|
61
|
+
block: false,
|
|
62
|
+
seekable: true,
|
|
63
|
+
tagName: 'include',
|
|
64
|
+
/**
|
|
65
|
+
* Compiles else block node to Javascript else statement
|
|
66
|
+
*/
|
|
67
|
+
compile(parser, buffer, token) {
|
|
68
|
+
const awaitKeyword = parser.asyncMode ? 'await ' : '';
|
|
69
|
+
const parsed = (0, utils_js_1.parseJsArg)(parser, token);
|
|
70
|
+
/**
|
|
71
|
+
* Only mentioned expressions are allowed inside `@include` tag
|
|
72
|
+
*/
|
|
73
|
+
(0, utils_js_1.isSubsetOf)(parsed, exports.ALLOWED_EXPRESSION, () => {
|
|
74
|
+
(0, utils_js_1.unallowedExpression)(`"${token.properties.jsArg}" is not a valid argument type for the @include tag`, token.filename, parser.utils.getExpressionLoc(parsed));
|
|
75
|
+
});
|
|
76
|
+
buffer.outputExpression(`${awaitKeyword}${getRenderExpression(parser, parsed)}`, token.filename, token.loc.start.line, false);
|
|
77
|
+
},
|
|
78
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* edge.js
|
|
4
|
+
*
|
|
5
|
+
* (c) EdgeJS
|
|
6
|
+
*
|
|
7
|
+
* For the full copyright and license information, please view the LICENSE
|
|
8
|
+
* file that was distributed with this source code.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.includeIfTag = void 0;
|
|
12
|
+
const edge_error_1 = require("edge-error");
|
|
13
|
+
const edge_parser_1 = require("edge-parser");
|
|
14
|
+
const include_js_1 = require("./include.js");
|
|
15
|
+
const utils_js_1 = require("../utils.js");
|
|
16
|
+
/**
|
|
17
|
+
* Include tag is used to include partials in the same scope of the parent
|
|
18
|
+
* template.
|
|
19
|
+
*
|
|
20
|
+
* ```edge
|
|
21
|
+
* @include('partials.header')
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
exports.includeIfTag = {
|
|
25
|
+
block: false,
|
|
26
|
+
seekable: true,
|
|
27
|
+
tagName: 'includeIf',
|
|
28
|
+
/**
|
|
29
|
+
* Compiles else block node to Javascript else statement
|
|
30
|
+
*/
|
|
31
|
+
compile(parser, buffer, token) {
|
|
32
|
+
const awaitKeyword = parser.asyncMode ? 'await ' : '';
|
|
33
|
+
const parsed = (0, utils_js_1.parseJsArg)(parser, token);
|
|
34
|
+
/**
|
|
35
|
+
* The include if only accepts the sequence expression
|
|
36
|
+
*/
|
|
37
|
+
(0, utils_js_1.isSubsetOf)(parsed, [edge_parser_1.expressions.SequenceExpression], () => {
|
|
38
|
+
(0, utils_js_1.unallowedExpression)(`"${token.properties.jsArg}" is not a valid argument type for the @includeIf tag`, token.filename, parser.utils.getExpressionLoc(parsed));
|
|
39
|
+
});
|
|
40
|
+
/**
|
|
41
|
+
* Disallow more than or less than 2 values for the sequence expression
|
|
42
|
+
*/
|
|
43
|
+
if (parsed.expressions.length !== 2) {
|
|
44
|
+
throw new edge_error_1.EdgeError('@includeIf expects a total of 2 arguments', 'E_ARGUMENTS_MIS_MATCH', {
|
|
45
|
+
line: parsed.loc.start.line,
|
|
46
|
+
col: parsed.loc.start.column,
|
|
47
|
+
filename: token.filename,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
const [conditional, include] = parsed.expressions;
|
|
51
|
+
(0, utils_js_1.isNotSubsetOf)(conditional, [edge_parser_1.expressions.SequenceExpression], () => {
|
|
52
|
+
(0, utils_js_1.unallowedExpression)(`"${conditional.type}" is not a valid 1st argument type for the @includeIf tag`, token.filename, parser.utils.getExpressionLoc(conditional));
|
|
53
|
+
});
|
|
54
|
+
(0, utils_js_1.isSubsetOf)(include, include_js_1.ALLOWED_EXPRESSION, () => {
|
|
55
|
+
(0, utils_js_1.unallowedExpression)(`"${include.type}" is not a valid 2nd argument type for the @includeIf tag`, token.filename, parser.utils.getExpressionLoc(include));
|
|
56
|
+
});
|
|
57
|
+
buffer.writeStatement(`if (${parser.utils.stringify(conditional)}) {`, token.filename, token.loc.start.line);
|
|
58
|
+
buffer.outputExpression(`${awaitKeyword}${(0, include_js_1.getRenderExpression)(parser, include)}`, token.filename, token.loc.start.line, false);
|
|
59
|
+
buffer.writeStatement('}', token.filename, -1);
|
|
60
|
+
},
|
|
61
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* edge.js
|
|
4
|
+
*
|
|
5
|
+
* (c) EdgeJS
|
|
6
|
+
*
|
|
7
|
+
* For the full copyright and license information, please view the LICENSE
|
|
8
|
+
* file that was distributed with this source code.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.injectTag = void 0;
|
|
12
|
+
const edge_parser_1 = require("edge-parser");
|
|
13
|
+
const utils_js_1 = require("../utils.js");
|
|
14
|
+
/**
|
|
15
|
+
* The inject tag is used within the components to share values with the
|
|
16
|
+
* component caller.
|
|
17
|
+
*/
|
|
18
|
+
exports.injectTag = {
|
|
19
|
+
block: false,
|
|
20
|
+
seekable: true,
|
|
21
|
+
tagName: 'inject',
|
|
22
|
+
noNewLine: true,
|
|
23
|
+
compile(parser, buffer, token) {
|
|
24
|
+
token.properties.jsArg = `(${token.properties.jsArg})`;
|
|
25
|
+
const parsed = (0, utils_js_1.parseJsArg)(parser, token);
|
|
26
|
+
/**
|
|
27
|
+
* The inject tag only accepts an object expression.
|
|
28
|
+
*/
|
|
29
|
+
(0, utils_js_1.isSubsetOf)(parsed, [edge_parser_1.expressions.ObjectExpression, edge_parser_1.expressions.Identifier, edge_parser_1.expressions.CallExpression], () => {
|
|
30
|
+
throw (0, utils_js_1.unallowedExpression)(`"${token.properties.jsArg}" is not a valid key-value pair for the @inject tag`, token.filename, parser.utils.getExpressionLoc(parsed));
|
|
31
|
+
});
|
|
32
|
+
/**
|
|
33
|
+
* Ensure $slots are defined before merging shared state
|
|
34
|
+
*/
|
|
35
|
+
buffer.writeStatement('if (!state.$slots || !state.$slots.$context) {', token.filename, token.loc.start.line);
|
|
36
|
+
buffer.writeExpression(`throw new Error('Cannot use "@inject" outside of a component scope')`, token.filename, token.loc.start.line);
|
|
37
|
+
buffer.writeStatement('}', token.filename, token.loc.start.line);
|
|
38
|
+
buffer.writeExpression(`Object.assign(state.$slots.$context, ${parser.utils.stringify(parsed)})`, token.filename, token.loc.start.line);
|
|
39
|
+
},
|
|
40
|
+
};
|
package/src/tags/let.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* edge.js
|
|
4
|
+
*
|
|
5
|
+
* (c) EdgeJS
|
|
6
|
+
*
|
|
7
|
+
* For the full copyright and license information, please view the LICENSE
|
|
8
|
+
* file that was distributed with this source code.
|
|
9
|
+
*/
|
|
10
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.letTag = void 0;
|
|
15
|
+
const edge_parser_1 = require("edge-parser");
|
|
16
|
+
const lodash_1 = __importDefault(require("@poppinss/utils/lodash"));
|
|
17
|
+
const utils_js_1 = require("../utils.js");
|
|
18
|
+
/**
|
|
19
|
+
* The let tag is used to set runtime values within the template. The value
|
|
20
|
+
* is set inside the current scope of the template.
|
|
21
|
+
*/
|
|
22
|
+
exports.letTag = {
|
|
23
|
+
block: false,
|
|
24
|
+
seekable: true,
|
|
25
|
+
tagName: 'let',
|
|
26
|
+
noNewLine: true,
|
|
27
|
+
/**
|
|
28
|
+
* Compiles else block node to Javascript else statement
|
|
29
|
+
*/
|
|
30
|
+
compile(parser, buffer, token) {
|
|
31
|
+
const parsed = parser.utils.generateAST(`let ${token.properties.jsArg}`, token.loc, token.filename).declarations[0];
|
|
32
|
+
const key = parsed.id;
|
|
33
|
+
const value = parsed.init;
|
|
34
|
+
/**
|
|
35
|
+
* The variable name has to be an identifier or the destructuring
|
|
36
|
+
* operator.
|
|
37
|
+
*/
|
|
38
|
+
(0, utils_js_1.isSubsetOf)(key, ['ObjectPattern', edge_parser_1.expressions.Identifier, 'ArrayPattern'], () => {
|
|
39
|
+
throw (0, utils_js_1.unallowedExpression)(`Invalid variable name for the @let tag`, token.filename, parser.utils.getExpressionLoc(key));
|
|
40
|
+
});
|
|
41
|
+
/**
|
|
42
|
+
* Define local variables based upon the expression
|
|
43
|
+
*/
|
|
44
|
+
if (key.type === 'Identifier') {
|
|
45
|
+
parser.stack.defineVariable(key.name);
|
|
46
|
+
}
|
|
47
|
+
else if (key.type === 'ObjectPattern') {
|
|
48
|
+
key.properties.forEach((property) => {
|
|
49
|
+
parser.stack.defineVariable(property.argument ? property.argument.name : property.value.name);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
else if (key.type === 'ArrayPattern') {
|
|
53
|
+
key.elements.forEach((element) => {
|
|
54
|
+
parser.stack.defineVariable(element.argument ? element.argument.name : element.name);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Declare let variable
|
|
59
|
+
*/
|
|
60
|
+
const expression = `let ${parser.utils.stringify(key)} = ${parser.utils.stringify(parser.utils.transformAst(value, token.filename, parser))}`;
|
|
61
|
+
buffer.writeExpression(expression, token.filename, token.loc.start.line);
|
|
62
|
+
},
|
|
63
|
+
/**
|
|
64
|
+
* Add methods to the template for running the loop
|
|
65
|
+
*/
|
|
66
|
+
boot(template) {
|
|
67
|
+
template.macro('setValue', lodash_1.default.set);
|
|
68
|
+
},
|
|
69
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { ifTag as if } from './if.js'
|
|
2
|
+
export { letTag as let } from './let.js'
|
|
3
|
+
export { eachTag as each } from './each.js'
|
|
4
|
+
export { slotTag as slot } from './slot.js'
|
|
5
|
+
export { elseTag as else } from './else.js'
|
|
6
|
+
export { evalTag as eval } from './eval.js'
|
|
7
|
+
export { stackTag as stack } from './stack.js'
|
|
8
|
+
export { assignTag as assign } from './assign.js'
|
|
9
|
+
export { injectTag as inject } from './inject.js'
|
|
10
|
+
export { unlessTag as unless } from './unless.js'
|
|
11
|
+
export { elseIfTag as elseif } from './else_if.js'
|
|
12
|
+
export { pushToTag as pushTo } from './push_to.js'
|
|
13
|
+
export { includeTag as include } from './include.js'
|
|
14
|
+
export { debuggerTag as debugger } from './debugger.js'
|
|
15
|
+
export { newErrorTag as newError } from './new_error.js'
|
|
16
|
+
export { componentTag as component } from './component.js'
|
|
17
|
+
export { includeIfTag as includeIf } from './include_if.js'
|
|
18
|
+
export { pushOnceToTag as pushOnceTo } from './push_once_to.js'
|
package/src/tags/main.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* edge.js
|
|
4
|
+
*
|
|
5
|
+
* (c) EdgeJS
|
|
6
|
+
*
|
|
7
|
+
* For the full copyright and license information, please view the LICENSE
|
|
8
|
+
* file that was distributed with this source code.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.pushOnceTo = exports.includeIf = exports.component = exports.newError = exports.debugger = exports.include = exports.pushTo = exports.elseif = exports.unless = exports.inject = exports.assign = exports.stack = exports.eval = exports.else = exports.slot = exports.each = exports.let = exports.if = void 0;
|
|
12
|
+
var if_js_1 = require("./if.js");
|
|
13
|
+
Object.defineProperty(exports, "if", { enumerable: true, get: function () { return if_js_1.ifTag; } });
|
|
14
|
+
var let_js_1 = require("./let.js");
|
|
15
|
+
Object.defineProperty(exports, "let", { enumerable: true, get: function () { return let_js_1.letTag; } });
|
|
16
|
+
var each_js_1 = require("./each.js");
|
|
17
|
+
Object.defineProperty(exports, "each", { enumerable: true, get: function () { return each_js_1.eachTag; } });
|
|
18
|
+
var slot_js_1 = require("./slot.js");
|
|
19
|
+
Object.defineProperty(exports, "slot", { enumerable: true, get: function () { return slot_js_1.slotTag; } });
|
|
20
|
+
var else_js_1 = require("./else.js");
|
|
21
|
+
Object.defineProperty(exports, "else", { enumerable: true, get: function () { return else_js_1.elseTag; } });
|
|
22
|
+
var eval_js_1 = require("./eval.js");
|
|
23
|
+
Object.defineProperty(exports, "eval", { enumerable: true, get: function () { return eval_js_1.evalTag; } });
|
|
24
|
+
var stack_js_1 = require("./stack.js");
|
|
25
|
+
Object.defineProperty(exports, "stack", { enumerable: true, get: function () { return stack_js_1.stackTag; } });
|
|
26
|
+
var assign_js_1 = require("./assign.js");
|
|
27
|
+
Object.defineProperty(exports, "assign", { enumerable: true, get: function () { return assign_js_1.assignTag; } });
|
|
28
|
+
var inject_js_1 = require("./inject.js");
|
|
29
|
+
Object.defineProperty(exports, "inject", { enumerable: true, get: function () { return inject_js_1.injectTag; } });
|
|
30
|
+
var unless_js_1 = require("./unless.js");
|
|
31
|
+
Object.defineProperty(exports, "unless", { enumerable: true, get: function () { return unless_js_1.unlessTag; } });
|
|
32
|
+
var else_if_js_1 = require("./else_if.js");
|
|
33
|
+
Object.defineProperty(exports, "elseif", { enumerable: true, get: function () { return else_if_js_1.elseIfTag; } });
|
|
34
|
+
var push_to_js_1 = require("./push_to.js");
|
|
35
|
+
Object.defineProperty(exports, "pushTo", { enumerable: true, get: function () { return push_to_js_1.pushToTag; } });
|
|
36
|
+
var include_js_1 = require("./include.js");
|
|
37
|
+
Object.defineProperty(exports, "include", { enumerable: true, get: function () { return include_js_1.includeTag; } });
|
|
38
|
+
var debugger_js_1 = require("./debugger.js");
|
|
39
|
+
Object.defineProperty(exports, "debugger", { enumerable: true, get: function () { return debugger_js_1.debuggerTag; } });
|
|
40
|
+
var new_error_js_1 = require("./new_error.js");
|
|
41
|
+
Object.defineProperty(exports, "newError", { enumerable: true, get: function () { return new_error_js_1.newErrorTag; } });
|
|
42
|
+
var component_js_1 = require("./component.js");
|
|
43
|
+
Object.defineProperty(exports, "component", { enumerable: true, get: function () { return component_js_1.componentTag; } });
|
|
44
|
+
var include_if_js_1 = require("./include_if.js");
|
|
45
|
+
Object.defineProperty(exports, "includeIf", { enumerable: true, get: function () { return include_if_js_1.includeIfTag; } });
|
|
46
|
+
var push_once_to_js_1 = require("./push_once_to.js");
|
|
47
|
+
Object.defineProperty(exports, "pushOnceTo", { enumerable: true, get: function () { return push_once_to_js_1.pushOnceToTag; } });
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* edge.js
|
|
4
|
+
*
|
|
5
|
+
* (c) EdgeJS
|
|
6
|
+
*
|
|
7
|
+
* For the full copyright and license information, please view the LICENSE
|
|
8
|
+
* file that was distributed with this source code.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.newErrorTag = void 0;
|
|
12
|
+
const edge_parser_1 = require("edge-parser");
|
|
13
|
+
const utils_js_1 = require("../utils.js");
|
|
14
|
+
/**
|
|
15
|
+
* newError tag to raise exceptions inside your templates. They will point
|
|
16
|
+
* back to the exact line:col in the template
|
|
17
|
+
*/
|
|
18
|
+
exports.newErrorTag = {
|
|
19
|
+
block: false,
|
|
20
|
+
seekable: true,
|
|
21
|
+
tagName: 'newError',
|
|
22
|
+
noNewLine: true,
|
|
23
|
+
compile(parser, buffer, token) {
|
|
24
|
+
const parsed = (0, utils_js_1.parseJsArg)(parser, token);
|
|
25
|
+
let message = '';
|
|
26
|
+
let line = token.loc.start.line;
|
|
27
|
+
let col = token.loc.start.col;
|
|
28
|
+
let filename = '$filename';
|
|
29
|
+
if (parsed.type === edge_parser_1.expressions.SequenceExpression) {
|
|
30
|
+
message = parser.utils.stringify(parsed.expressions[0]);
|
|
31
|
+
filename = parsed.expressions[1] ? parser.utils.stringify(parsed.expressions[1]) : '$filename';
|
|
32
|
+
line = parsed.expressions[2]
|
|
33
|
+
? parser.utils.stringify(parsed.expressions[2])
|
|
34
|
+
: token.loc.start.line;
|
|
35
|
+
col = parsed.expressions[3]
|
|
36
|
+
? parser.utils.stringify(parsed.expressions[3])
|
|
37
|
+
: token.loc.start.col;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
message = parser.utils.stringify(parsed);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Raise the exception with the correct filename and the line number
|
|
44
|
+
*/
|
|
45
|
+
buffer.writeStatement(`template.newError(${message}, ${filename}, ${line}, ${col})`, token.filename, token.loc.start.line);
|
|
46
|
+
},
|
|
47
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type TagContract } from '../types.js'
|
|
2
|
+
declare module '../template.js' {
|
|
3
|
+
interface Template {
|
|
4
|
+
stackSources: Record<string, boolean>
|
|
5
|
+
trackStackSource(stack: string, filename: string, line: string, col: string): boolean
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Stack tag to define stack placeholders
|
|
10
|
+
*/
|
|
11
|
+
export declare const pushOnceToTag: TagContract & {
|
|
12
|
+
generateId(): string
|
|
13
|
+
}
|