@marko/translator-default 5.28.2 → 5.29.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.
|
@@ -1,35 +1,17 @@
|
|
|
1
|
-
"use strict";exports.__esModule = true;exports.default = _default;
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
"use strict";exports.__esModule = true;exports.default = _default;var _compiler = require("@marko/compiler");
|
|
2
|
+
var _babelUtils = require("@marko/babel-utils");
|
|
3
|
+
|
|
4
|
+
function _default(path) {
|
|
5
|
+
const attrs = path.node.attributes;
|
|
6
|
+
if (attrs.length === 1) {
|
|
7
|
+
const [attr] = attrs;
|
|
8
|
+
|
|
9
|
+
if (
|
|
10
|
+
_compiler.types.isMarkoAttribute(attr) &&
|
|
11
|
+
attr.name === "name" &&
|
|
12
|
+
_compiler.types.isStringLiteral(attr.value))
|
|
13
|
+
{
|
|
14
|
+
(0, _babelUtils.registerMacro)(path.get("attributes")[0], attr.value.value);
|
|
15
|
+
}
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
-
const nameAttrValue = nameAttr.get("value");
|
|
18
|
-
|
|
19
|
-
if (!nameAttrValue.isStringLiteral()) {
|
|
20
|
-
throw nameAttrValue.buildCodeFrameError(
|
|
21
|
-
'The "name" attribute for "macro" tags must be a string literal.');
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const name = nameAttrValue.node.value;
|
|
26
|
-
const { file } = path.hub;
|
|
27
|
-
|
|
28
|
-
if (file.metadata.marko.macros[name]) {
|
|
29
|
-
throw nameAttr.buildCodeFrameError(
|
|
30
|
-
`A macro with the name "${name}" already exists.`);
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
file.metadata.marko.macros[name] = file.scope.generateUid(name);
|
|
35
17
|
}
|
|
@@ -1,15 +1,40 @@
|
|
|
1
1
|
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.exit = exit;var _compiler = require("@marko/compiler");
|
|
2
2
|
var _withPreviousLocation = _interopRequireDefault(require("../../../util/with-previous-location"));
|
|
3
|
+
var _babelUtils = require("@marko/babel-utils");
|
|
3
4
|
|
|
4
5
|
function exit(path) {
|
|
5
6
|
const { node } = path;
|
|
6
|
-
const { body } = node;
|
|
7
|
-
|
|
7
|
+
const { attributes, body } = node;
|
|
8
|
+
if (attributes.length === 0) {
|
|
9
|
+
(0, _babelUtils.diagnosticError)(path, {
|
|
10
|
+
label: "The 'macro' tag must have a 'name' attribute."
|
|
11
|
+
});
|
|
12
|
+
path.remove();
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (attributes.length > 1) {
|
|
17
|
+
(0, _babelUtils.diagnosticError)(path, {
|
|
18
|
+
label: "The 'macro' tag can only have a 'name' attribute."
|
|
19
|
+
});
|
|
20
|
+
path.remove();
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const [nameAttr] = attributes;
|
|
25
|
+
if (!_compiler.types.isStringLiteral(nameAttr.value)) {
|
|
26
|
+
(0, _babelUtils.diagnosticError)(path, {
|
|
27
|
+
label: "The 'name' attribute for 'macro' tags must be a string literal.",
|
|
28
|
+
loc: nameAttr.loc || node.loc || undefined
|
|
29
|
+
});
|
|
30
|
+
path.remove();
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
8
33
|
|
|
9
34
|
path.replaceWith(
|
|
10
35
|
(0, _withPreviousLocation.default)(
|
|
11
36
|
_compiler.types.functionDeclaration(
|
|
12
|
-
|
|
37
|
+
(0, _babelUtils.getMacroIdentifierForName)(path, nameAttr.value.value),
|
|
13
38
|
[_compiler.types.identifier("out"), ...body.params],
|
|
14
39
|
_compiler.types.blockStatement(body.body)),
|
|
15
40
|
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.default = _default;var _compiler = require("@marko/compiler");
|
|
2
2
|
var _babelUtils = require("@marko/babel-utils");
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
3
7
|
var _getComponentFiles = _interopRequireDefault(require("../../util/get-component-files"));
|
|
4
8
|
|
|
5
9
|
function _default(path) {
|
|
@@ -13,48 +17,59 @@ function _default(path) {
|
|
|
13
17
|
} = node;
|
|
14
18
|
const meta = file.metadata.marko;
|
|
15
19
|
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
if (meta.hasComponent) {
|
|
21
|
+
(0, _babelUtils.diagnosticError)(path.get("name"), {
|
|
22
|
+
label: "A Marko component can only have one top level class."
|
|
23
|
+
});
|
|
24
|
+
path.remove();
|
|
25
|
+
return;
|
|
22
26
|
}
|
|
23
27
|
|
|
24
|
-
|
|
25
|
-
throw path.
|
|
26
|
-
get("name").
|
|
27
|
-
buildCodeFrameError(
|
|
28
|
-
"A Marko component can only have one top level class.");
|
|
28
|
+
meta.hasComponent = true;
|
|
29
29
|
|
|
30
|
+
if ((0, _getComponentFiles.default)(path).componentFile) {
|
|
31
|
+
(0, _babelUtils.diagnosticError)(path.get("name"), {
|
|
32
|
+
label:
|
|
33
|
+
'A Marko file can either have an inline class, or an external "component.js", but not both.'
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
path.remove();
|
|
37
|
+
return;
|
|
30
38
|
}
|
|
31
39
|
|
|
32
40
|
const parsed = (0, _babelUtils.parseExpression)(file, code.replace(/;\s*$/, ""), start, end);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
parsed.id,
|
|
37
|
-
"Component class cannot have a name.");
|
|
38
|
-
|
|
41
|
+
if (parsed.type === "MarkoParseError") {
|
|
42
|
+
path.replaceWith(_compiler.types.markoClass([_compiler.types.expressionStatement(parsed)]));
|
|
43
|
+
return;
|
|
39
44
|
}
|
|
40
45
|
|
|
41
46
|
if (parsed.superClass) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
(0, _babelUtils.diagnosticError)(path, {
|
|
48
|
+
label: "Component class cannot have a super class.",
|
|
49
|
+
loc: parsed.superClass.loc
|
|
50
|
+
});
|
|
46
51
|
}
|
|
47
52
|
|
|
48
|
-
const
|
|
53
|
+
const constructorPropIndex = parsed.body.body.findIndex(
|
|
49
54
|
(prop) => _compiler.types.isClassMethod(prop) && prop.kind === "constructor");
|
|
50
55
|
|
|
51
|
-
if (
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
56
|
+
if (constructorPropIndex !== -1) {
|
|
57
|
+
const constructorProp = parsed.body.body[constructorPropIndex];
|
|
58
|
+
(0, _babelUtils.diagnosticError)(path, {
|
|
59
|
+
label:
|
|
60
|
+
"The constructor method should not be used for a component, use onCreate instead.",
|
|
61
|
+
loc: constructorProp.key.loc
|
|
62
|
+
});
|
|
55
63
|
|
|
64
|
+
parsed.body.body.splice(constructorProp, 1);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (parsed.id) {
|
|
68
|
+
(0, _babelUtils.diagnosticDeprecate)(path, {
|
|
69
|
+
label: "Component class should not have a name.",
|
|
70
|
+
loc: parsed.id.loc
|
|
71
|
+
});
|
|
56
72
|
}
|
|
57
73
|
|
|
58
|
-
meta.hasComponent = true;
|
|
59
74
|
path.replaceWith(_compiler.types.markoClass(parsed.body));
|
|
60
75
|
}
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marko/translator-default",
|
|
3
3
|
"description": "Translates Marko templates to the default Marko runtime.",
|
|
4
|
-
"version": "5.
|
|
4
|
+
"version": "5.29.0",
|
|
5
5
|
"author": "Dylan Piercey <dpiercey@ebay.com>",
|
|
6
6
|
"bugs": "https://github.com/marko-js/marko/issues/new?template=Bug_report.md",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@babel/runtime": "^7.16.0",
|
|
9
|
-
"@marko/babel-utils": "^6.
|
|
9
|
+
"@marko/babel-utils": "^6.2.0",
|
|
10
10
|
"escape-string-regexp": "^4.0.0",
|
|
11
11
|
"magic-string": "^0.27.0",
|
|
12
12
|
"self-closing-tags": "^1.0.1"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
|
-
"@marko/compiler": "^5.
|
|
16
|
-
"marko": "^5.
|
|
15
|
+
"@marko/compiler": "^5.31.0",
|
|
16
|
+
"marko": "^5.29.0"
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
19
|
"dist",
|