@marko/translator-default 5.31.13 → 5.31.14

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -505,9 +505,7 @@ function getRuntimeEntryFiles(output, optimize) {
505
505
  `${base}runtime/vdom/index.js`,
506
506
  `${base}runtime/vdom/hot-reload.js`,
507
507
  `${base}runtime/vdom/helpers/attrs.js`,
508
- `${base}runtime/vdom/helpers/const.js`,
509
- `${base}runtime/vdom/helpers/v-element.js`,
510
- `${base}runtime/vdom/helpers/v-text.js`,
508
+ `${base}runtime/vdom/helpers/const-element.js`,
511
509
  `${base}runtime/vdom/preserve-attrs.js`])];
512
510
 
513
511
 
@@ -1,4 +1,4 @@
1
- "use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.default = _default;exports.tagArguments = tagArguments;var _babelUtils = require("@marko/babel-utils");
1
+ "use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.default = _default;var _babelUtils = require("@marko/babel-utils");
2
2
  var _compiler = require("@marko/compiler");
3
3
  var FLAGS = _interopRequireWildcard(require("../../util/runtime-flags"));
4
4
  var _vdomOutWrite = _interopRequireDefault(require("../../util/vdom-out-write"));
@@ -7,7 +7,85 @@ var _attributes = _interopRequireDefault(require("./attributes"));function _getR
7
7
 
8
8
  const SIMPLE_ATTRS = ["id", "class", "style"];
9
9
 
10
- function tagArguments(path, isStatic) {
10
+ /**
11
+ * Translates the html streaming version of a standard html element.
12
+ */
13
+ function _default(path, isNullable) {
14
+ const { node } = path;
15
+ const {
16
+ name,
17
+ key,
18
+ body: { body }
19
+ } = node;
20
+
21
+ const isEmpty = !body.length;
22
+ const writeArgs = tagArguments(path, false);
23
+ let writeStartNode = (0, _withPreviousLocation.default)(
24
+ (0, _vdomOutWrite.default)(isEmpty ? "e" : "be", ...writeArgs),
25
+ node.name
26
+ );
27
+
28
+ if (isNullable) {
29
+ writeStartNode = _compiler.types.ifStatement(
30
+ name,
31
+ writeStartNode,
32
+ _compiler.types.expressionStatement(
33
+ _compiler.types.callExpression(
34
+ _compiler.types.memberExpression(_compiler.types.identifier("out"), _compiler.types.identifier("bf")),
35
+ [
36
+ (0, _babelUtils.normalizeTemplateString)`f_${key}`,
37
+ path.hub.file._componentInstanceIdentifier]
38
+
39
+ )
40
+ )
41
+ );
42
+ }
43
+
44
+ if (isEmpty) {
45
+ path.replaceWith(writeStartNode);
46
+ return;
47
+ }
48
+
49
+ let writeEndNode = (0, _vdomOutWrite.default)("ee");
50
+ if (isNullable) {
51
+ writeEndNode = _compiler.types.ifStatement(
52
+ name,
53
+ writeEndNode,
54
+ _compiler.types.expressionStatement(
55
+ _compiler.types.callExpression(
56
+ _compiler.types.memberExpression(_compiler.types.identifier("out"), _compiler.types.identifier("ef")),
57
+ []
58
+ )
59
+ )
60
+ );
61
+ }
62
+
63
+ let needsBlock;
64
+ for (const childNode of body) {
65
+ if (_compiler.types.isVariableDeclaration(childNode)) {
66
+ if (childNode.kind === "const" || childNode.kind === "let") {
67
+ needsBlock = true;
68
+ break;
69
+ }
70
+ }
71
+ }
72
+
73
+ path.replaceWithMultiple(
74
+ [writeStartNode].
75
+ concat(needsBlock ? _compiler.types.blockStatement(body) : body).
76
+ concat(writeEndNode)
77
+ );
78
+ }
79
+
80
+ function isPropertyName({ key }, names) {
81
+ if (_compiler.types.isStringLiteral(key)) {
82
+ return names.includes(key.value);
83
+ } else if (_compiler.types.isIdentifier(key)) {
84
+ return names.includes(key.name);
85
+ }
86
+ }
87
+
88
+ function tagArguments(path) {
11
89
  const {
12
90
  hub: { file },
13
91
  node
@@ -29,13 +107,9 @@ function tagArguments(path, isStatic) {
29
107
  const writeArgs = [
30
108
  name,
31
109
  attrsObj,
32
- !key && isStatic ? _compiler.types.nullLiteral() : key,
33
- isStatic ? _compiler.types.nullLiteral() : file._componentInstanceIdentifier,
34
- isStatic ?
35
- _compiler.types.numericLiteral(body.length) :
36
- body.length ?
37
- _compiler.types.nullLiteral() :
38
- _compiler.types.numericLiteral(0)];
110
+ key,
111
+ file._componentInstanceIdentifier,
112
+ body.length ? _compiler.types.nullLiteral() : _compiler.types.numericLiteral(0)];
39
113
 
40
114
 
41
115
  if (node.preserveAttrs) {
@@ -101,82 +175,4 @@ function tagArguments(path, isStatic) {
101
175
  writeArgs.push(_compiler.types.objectExpression(tagProperties));
102
176
  }
103
177
  return writeArgs;
104
- }
105
-
106
- /**
107
- * Translates the html streaming version of a standard html element.
108
- */
109
- function _default(path, isNullable) {
110
- const { node } = path;
111
- const {
112
- name,
113
- key,
114
- body: { body }
115
- } = node;
116
-
117
- const isEmpty = !body.length;
118
- const writeArgs = tagArguments(path, false);
119
- let writeStartNode = (0, _withPreviousLocation.default)(
120
- (0, _vdomOutWrite.default)(isEmpty ? "e" : "be", ...writeArgs),
121
- node.name
122
- );
123
-
124
- if (isNullable) {
125
- writeStartNode = _compiler.types.ifStatement(
126
- name,
127
- writeStartNode,
128
- _compiler.types.expressionStatement(
129
- _compiler.types.callExpression(
130
- _compiler.types.memberExpression(_compiler.types.identifier("out"), _compiler.types.identifier("bf")),
131
- [
132
- (0, _babelUtils.normalizeTemplateString)`f_${key}`,
133
- path.hub.file._componentInstanceIdentifier]
134
-
135
- )
136
- )
137
- );
138
- }
139
-
140
- if (isEmpty) {
141
- path.replaceWith(writeStartNode);
142
- return;
143
- }
144
-
145
- let writeEndNode = (0, _vdomOutWrite.default)("ee");
146
- if (isNullable) {
147
- writeEndNode = _compiler.types.ifStatement(
148
- name,
149
- writeEndNode,
150
- _compiler.types.expressionStatement(
151
- _compiler.types.callExpression(
152
- _compiler.types.memberExpression(_compiler.types.identifier("out"), _compiler.types.identifier("ef")),
153
- []
154
- )
155
- )
156
- );
157
- }
158
-
159
- let needsBlock;
160
- for (const childNode of body) {
161
- if (_compiler.types.isVariableDeclaration(childNode)) {
162
- if (childNode.kind === "const" || childNode.kind === "let") {
163
- needsBlock = true;
164
- break;
165
- }
166
- }
167
- }
168
-
169
- path.replaceWithMultiple(
170
- [writeStartNode].
171
- concat(needsBlock ? _compiler.types.blockStatement(body) : body).
172
- concat(writeEndNode)
173
- );
174
- }
175
-
176
- function isPropertyName({ key }, names) {
177
- if (_compiler.types.isStringLiteral(key)) {
178
- return names.includes(key.value);
179
- } else if (_compiler.types.isIdentifier(key)) {
180
- return names.includes(key.name);
181
- }
182
178
  }
@@ -7,7 +7,7 @@
7
7
 
8
8
  var _compiler = require("@marko/compiler");
9
9
  var _he = require("he");
10
- var _nativeTagVdom = require("../tag/native-tag[vdom]");
10
+ var _attributes = _interopRequireDefault(require("../tag/native-tag[vdom]/attributes"));
11
11
  var _keyManager = require("./key-manager");
12
12
  var _vdomOutWrite = _interopRequireDefault(require("./vdom-out-write"));
13
13
 
@@ -40,10 +40,9 @@ const mergeStaticCreateVisitor = {
40
40
  },
41
41
  MarkoTag(path, state) {
42
42
  (0, _keyManager.getKeyManager)(path).resolveKey(path);
43
- const writeArgs = (0, _nativeTagVdom.tagArguments)(path, true);
44
43
  state.currentRoot = _compiler.types.callExpression(
45
44
  _compiler.types.memberExpression(state.currentRoot, _compiler.types.identifier("e")),
46
- writeArgs
45
+ getConstElementArgs(path)
47
46
  );
48
47
  }
49
48
  };
@@ -70,7 +69,8 @@ const analyzeStaticVisitor = {
70
69
  let isStatic =
71
70
  (0, _babelUtils.isNativeTag)(path) &&
72
71
  !path.node.body.params.length &&
73
- !path.node.arguments;
72
+ !path.node.arguments &&
73
+ !(0, _keyManager.hasUserKey)(path);
74
74
 
75
75
  const tagDef = (0, _babelUtils.getTagDef)(path);
76
76
  isStatic = isStatic && !tagDef.translator;
@@ -118,15 +118,14 @@ function optimizeStaticVDOM(path) {
118
118
  }
119
119
 
120
120
  const identifier = path.scope.generateUidIdentifier("marko_node");
121
- const writeArgs = (0, _nativeTagVdom.tagArguments)(path, true);
122
121
  const state = {
123
122
  currentRoot: _compiler.types.callExpression(
124
123
  (0, _babelUtils.importDefault)(
125
124
  file,
126
- "marko/src/runtime/vdom/helpers/v-element.js",
127
- "marko_createElement"
125
+ "marko/src/runtime/vdom/helpers/const-element.js",
126
+ "marko_constElement"
128
127
  ),
129
- writeArgs
128
+ getConstElementArgs(path)
130
129
  )
131
130
  };
132
131
 
@@ -148,4 +147,13 @@ function analyzeStaticVDOM(path) {
148
147
 
149
148
  function shouldRun(markoOpts) {
150
149
  return markoOpts.optimize && markoOpts.output !== "html";
150
+ }
151
+
152
+ function getConstElementArgs(path) {
153
+ const { node } = path;
154
+ return [
155
+ node.name,
156
+ (0, _attributes.default)(path, path.get("attributes")),
157
+ _compiler.types.numericLiteral(node.body.body.length)];
158
+
151
159
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marko/translator-default",
3
- "version": "5.31.13",
3
+ "version": "5.31.14",
4
4
  "description": "Translates Marko templates to the default Marko runtime.",
5
5
  "keywords": [
6
6
  "babel",
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "devDependencies": {
37
37
  "@marko/compiler": "^5.34.6",
38
- "marko": "^5.32.7"
38
+ "marko": "^5.32.8"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "@marko/compiler": "^5.16.1",