@marko/compiler 5.39.14 → 5.39.15
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/babel-plugin/index.js +137 -115
- package/dist/index.js +3 -2
- package/index.d.ts +3 -0
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.default = void 0;exports.
|
|
1
|
+
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.default = void 0;exports.getFile = getFile;exports.getProgram = getProgram;var _traverse = _interopRequireDefault(require("@babel/traverse"));
|
|
2
2
|
var _babelUtils = require("@marko/compiler/babel-utils");
|
|
3
3
|
var _crypto = require("crypto");
|
|
4
4
|
var _path = _interopRequireDefault(require("path"));
|
|
@@ -15,7 +15,8 @@ var _parser = require("./parser");
|
|
|
15
15
|
var _migrate = require("./plugins/migrate");
|
|
16
16
|
var _transform = require("./plugins/transform");function _getRequireWildcardCache(e) {if ("function" != typeof WeakMap) return null;var r = new WeakMap(),t = new WeakMap();return (_getRequireWildcardCache = function (e) {return e ? t : r;})(e);}function _interopRequireWildcard(e, r) {if (!r && e && e.__esModule) return e;if (null === e || "object" != typeof e && "function" != typeof e) return { default: e };var t = _getRequireWildcardCache(r);if (t && t.has(e)) return t.get(e);var n = { __proto__: null },a = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) {var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];}return n.default = e, t && t.set(e, n), n;}
|
|
17
17
|
|
|
18
|
-
const SOURCE_FILES = new WeakMap();
|
|
18
|
+
const SOURCE_FILES = new WeakMap();
|
|
19
|
+
let currentFile;var _default =
|
|
19
20
|
|
|
20
21
|
(api, markoOpts) => {
|
|
21
22
|
api.assertVersion(7);
|
|
@@ -61,22 +62,18 @@ const SOURCE_FILES = new WeakMap();var _default =
|
|
|
61
62
|
curOpts = opts;
|
|
62
63
|
},
|
|
63
64
|
parserOverride(code) {
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const finalAst = t.cloneNode(file.ast, true);
|
|
69
|
-
SOURCE_FILES.set(finalAst, file);
|
|
70
|
-
return finalAst;
|
|
71
|
-
} finally {
|
|
72
|
-
_config.default.fs = prevFS;
|
|
73
|
-
}
|
|
65
|
+
const file = getMarkoFile(code, curOpts, markoOpts);
|
|
66
|
+
const finalAst = t.cloneNode(file.ast, true);
|
|
67
|
+
SOURCE_FILES.set(finalAst, file);
|
|
68
|
+
return finalAst;
|
|
74
69
|
},
|
|
75
70
|
pre(file) {
|
|
76
71
|
const { buildError: prevBuildError } = file.hub;
|
|
77
72
|
const { buildCodeFrameError: prevCodeFrameError } = file;
|
|
78
73
|
const prevFS = _config.default.fs;
|
|
74
|
+
const prevFile = currentFile;
|
|
79
75
|
_config.default.fs = markoOpts.fileSystem;
|
|
76
|
+
currentFile = file;
|
|
80
77
|
curOpts = undefined;
|
|
81
78
|
try {
|
|
82
79
|
const { ast, metadata } = file;
|
|
@@ -114,6 +111,7 @@ const SOURCE_FILES = new WeakMap();var _default =
|
|
|
114
111
|
file.path.scope.crawl(); // Ensure all scopes are accurate for subsequent babel plugins
|
|
115
112
|
} finally {
|
|
116
113
|
_config.default.fs = prevFS;
|
|
114
|
+
currentFile = prevFile;
|
|
117
115
|
file.buildCodeFrameError = prevCodeFrameError;
|
|
118
116
|
file.hub.buildError = prevBuildError;
|
|
119
117
|
file.markoOpts =
|
|
@@ -147,6 +145,22 @@ const SOURCE_FILES = new WeakMap();var _default =
|
|
|
147
145
|
};
|
|
148
146
|
};exports.default = _default;
|
|
149
147
|
|
|
148
|
+
function getFile() {
|
|
149
|
+
if (currentFile) {
|
|
150
|
+
return currentFile;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
throw new Error("Unable to access Marko File outside of a compilation");
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function getProgram() {
|
|
157
|
+
if (currentFile) {
|
|
158
|
+
return currentFile.path;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
throw new Error("Unable to access Marko Program outside of a compilation");
|
|
162
|
+
}
|
|
163
|
+
|
|
150
164
|
function getMarkoFile(code, fileOpts, markoOpts) {
|
|
151
165
|
const { translator } = markoOpts;
|
|
152
166
|
let compileCache = markoOpts.cache.get(translator);
|
|
@@ -191,129 +205,137 @@ function getMarkoFile(code, fileOpts, markoOpts) {
|
|
|
191
205
|
return cached.file;
|
|
192
206
|
}
|
|
193
207
|
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
208
|
+
const prevFs = _config.default.fs;
|
|
209
|
+
const prevFile = currentFile;
|
|
210
|
+
_config.default.fs = markoOpts.fileSystem;
|
|
211
|
+
|
|
212
|
+
try {
|
|
213
|
+
const taglibLookup = (0, _taglib.buildLookup)(_path.default.dirname(filename), translator);
|
|
214
|
+
const file = currentFile = new _file.MarkoFile(fileOpts, {
|
|
215
|
+
code,
|
|
216
|
+
ast: {
|
|
217
|
+
type: "File",
|
|
218
|
+
program: {
|
|
219
|
+
type: "Program",
|
|
220
|
+
sourceType: "module",
|
|
221
|
+
body: [],
|
|
222
|
+
directives: [],
|
|
223
|
+
params: [t.identifier("input")]
|
|
224
|
+
}
|
|
206
225
|
}
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
const meta = file.metadata.marko = {
|
|
211
|
-
id,
|
|
212
|
-
deps: [],
|
|
213
|
-
tags: [],
|
|
214
|
-
watchFiles: [],
|
|
215
|
-
diagnostics: []
|
|
216
|
-
};
|
|
226
|
+
});
|
|
217
227
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
228
|
+
const meta = file.metadata.marko = {
|
|
229
|
+
id,
|
|
230
|
+
deps: [],
|
|
231
|
+
tags: [],
|
|
232
|
+
watchFiles: [],
|
|
233
|
+
diagnostics: []
|
|
234
|
+
};
|
|
221
235
|
|
|
222
|
-
|
|
223
|
-
|
|
236
|
+
file.markoOpts = markoOpts;
|
|
237
|
+
file.___taglibLookup = taglibLookup;
|
|
238
|
+
file.___getMarkoFile = getMarkoFile;
|
|
224
239
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
240
|
+
file.___compileStage = "parse";
|
|
241
|
+
(0, _parser.parseMarko)(file);
|
|
242
|
+
|
|
243
|
+
if (isSource) {
|
|
244
|
+
return file;
|
|
245
|
+
}
|
|
228
246
|
|
|
229
|
-
|
|
247
|
+
file.path.scope.crawl(); // Initialize bindings.
|
|
230
248
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
249
|
+
const rootMigrators = [];
|
|
250
|
+
for (const id in taglibLookup.taglibsById) {
|
|
251
|
+
for (const migrator of taglibLookup.taglibsById[id].migrators) {
|
|
252
|
+
addPlugin(meta, rootMigrators, migrator);
|
|
253
|
+
}
|
|
235
254
|
}
|
|
236
|
-
}
|
|
237
255
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
256
|
+
rootMigrators.push(_migrate.visitor);
|
|
257
|
+
file.___compileStage = "migrate";
|
|
258
|
+
traverseAll(file, rootMigrators);
|
|
259
|
+
|
|
260
|
+
if (file.___hasParseErrors) {
|
|
261
|
+
if (markoOpts.errorRecovery) {
|
|
262
|
+
t.traverseFast(file.path.node, (node) => {
|
|
263
|
+
if (node.type === "MarkoParseError") {
|
|
264
|
+
(0, _babelUtils.diagnosticError)(file.path, {
|
|
265
|
+
label: node.label,
|
|
266
|
+
loc: node.errorLoc || node.loc
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
} else {
|
|
271
|
+
let errors = [];
|
|
272
|
+
t.traverseFast(file.path.node, (node) => {
|
|
273
|
+
if (node.type === "MarkoParseError") {
|
|
274
|
+
errors.push(
|
|
275
|
+
(0, _buildCodeFrame.buildCodeFrameError)(
|
|
276
|
+
file.opts.filename,
|
|
277
|
+
file.code,
|
|
278
|
+
node.errorLoc || node.loc,
|
|
279
|
+
node.label
|
|
280
|
+
)
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
});
|
|
266
284
|
|
|
267
|
-
|
|
285
|
+
(0, _mergeErrors.default)(errors);
|
|
286
|
+
}
|
|
268
287
|
}
|
|
269
|
-
}
|
|
270
288
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
289
|
+
if (isMigrate) {
|
|
290
|
+
return file;
|
|
291
|
+
}
|
|
274
292
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
293
|
+
const rootTransformers = [];
|
|
294
|
+
for (const id in taglibLookup.taglibsById) {
|
|
295
|
+
for (const transformer of taglibLookup.taglibsById[id].transformers) {
|
|
296
|
+
addPlugin(meta, rootTransformers, transformer);
|
|
297
|
+
}
|
|
279
298
|
}
|
|
280
|
-
}
|
|
281
299
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
300
|
+
rootTransformers.push(_transform.visitor);
|
|
301
|
+
if (translator.transform) {
|
|
302
|
+
rootTransformers.push(translator.transform);
|
|
303
|
+
}
|
|
304
|
+
file.___compileStage = "transform";
|
|
305
|
+
traverseAll(file, rootTransformers);
|
|
288
306
|
|
|
289
|
-
|
|
290
|
-
|
|
307
|
+
for (const taglibId in taglibLookup.taglibsById) {
|
|
308
|
+
const { filePath } = taglibLookup.taglibsById[taglibId];
|
|
291
309
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
310
|
+
if (
|
|
311
|
+
filePath[filePath.length - 5] === "." &&
|
|
312
|
+
filePath.endsWith("marko.json"))
|
|
313
|
+
{
|
|
314
|
+
meta.watchFiles.push(filePath);
|
|
315
|
+
}
|
|
297
316
|
}
|
|
298
|
-
}
|
|
299
317
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
318
|
+
compileCache.set(cacheKey, {
|
|
319
|
+
time: Date.now(),
|
|
320
|
+
file,
|
|
321
|
+
contentHash
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
if (translator.analyze) {
|
|
325
|
+
try {
|
|
326
|
+
file.___compileStage = "analyze";
|
|
327
|
+
traverseAll(file, translator.analyze);
|
|
328
|
+
} catch (e) {
|
|
329
|
+
compileCache.delete(cacheKey);
|
|
330
|
+
throw e;
|
|
331
|
+
}
|
|
313
332
|
}
|
|
314
|
-
}
|
|
315
333
|
|
|
316
|
-
|
|
334
|
+
return file;
|
|
335
|
+
} finally {
|
|
336
|
+
_config.default.fs = prevFs;
|
|
337
|
+
currentFile = prevFile;
|
|
338
|
+
}
|
|
317
339
|
}
|
|
318
340
|
|
|
319
341
|
function shallowClone(data) {
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports._clearDefaults = _clearDefaults;exports.compile = compile;exports.compileFile = compileFile;exports.compileFileSync = compileFileSync;exports.compileSync = compileSync;exports.configure = configure;exports.getRuntimeEntryFiles = getRuntimeEntryFiles;exports.types = exports.taglib = exports.globalConfig = void 0;var _types = _interopRequireWildcard(require("./babel-types"));exports.types = _types;
|
|
1
|
+
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports._clearDefaults = _clearDefaults;exports.compile = compile;exports.compileFile = compileFile;exports.compileFileSync = compileFileSync;exports.compileSync = compileSync;exports.configure = configure;exports.getProgram = exports.getFile = void 0;exports.getRuntimeEntryFiles = getRuntimeEntryFiles;exports.types = exports.taglib = exports.globalConfig = void 0;var _types = _interopRequireWildcard(require("./babel-types"));exports.types = _types;
|
|
2
2
|
var babel = _interopRequireWildcard(require("@babel/core"));
|
|
3
3
|
var _pluginSyntaxTypescript = _interopRequireDefault(require("@babel/plugin-syntax-typescript"));
|
|
4
4
|
var _pluginTransformModulesCommonjs = _interopRequireDefault(require("@babel/plugin-transform-modules-commonjs"));
|
|
@@ -6,7 +6,7 @@ var _pluginTransformTypescript = _interopRequireDefault(require("@babel/plugin-t
|
|
|
6
6
|
var _babelUtils = require("@marko/compiler/babel-utils");
|
|
7
7
|
var _path = _interopRequireDefault(require("path"));
|
|
8
8
|
|
|
9
|
-
var _babelPlugin =
|
|
9
|
+
var _babelPlugin = _interopRequireWildcard(require("./babel-plugin"));exports.getFile = _babelPlugin.getFile;exports.getProgram = _babelPlugin.getProgram;
|
|
10
10
|
var _config = _interopRequireDefault(require("./config"));
|
|
11
11
|
var taglib = _interopRequireWildcard(require("./taglib"));exports.taglib = taglib;
|
|
12
12
|
var _buildCodeFrame = require("./util/build-code-frame");
|
|
@@ -15,6 +15,7 @@ var _shouldOptimize = _interopRequireDefault(require("./util/should-optimize"));
|
|
|
15
15
|
var _tryLoadTranslator = _interopRequireDefault(require("./util/try-load-translator"));function _getRequireWildcardCache(e) {if ("function" != typeof WeakMap) return null;var r = new WeakMap(),t = new WeakMap();return (_getRequireWildcardCache = function (e) {return e ? t : r;})(e);}function _interopRequireWildcard(e, r) {if (!r && e && e.__esModule) return e;if (null === e || "object" != typeof e && "function" != typeof e) return { default: e };var t = _getRequireWildcardCache(r);if (t && t.has(e)) return t.get(e);var n = { __proto__: null },a = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) {var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];}return n.default = e, t && t.set(e, n), n;}
|
|
16
16
|
|
|
17
17
|
|
|
18
|
+
|
|
18
19
|
const CWD = process.cwd();
|
|
19
20
|
|
|
20
21
|
let globalConfig = exports.globalConfig = { ..._config.default };
|
package/index.d.ts
CHANGED
|
@@ -69,6 +69,9 @@ export function getRuntimeEntryFiles(
|
|
|
69
69
|
translator?: string | undefined,
|
|
70
70
|
): string[];
|
|
71
71
|
|
|
72
|
+
export function getFile(): types.BabelFile;
|
|
73
|
+
export function getProgram(): types.NodePath<types.Program>;
|
|
74
|
+
|
|
72
75
|
export namespace taglib {
|
|
73
76
|
export function resolveOptionalTaglibs(
|
|
74
77
|
taglibIds: string[],
|