@marko/compiler 5.21.0 → 5.21.1
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/package.json +4 -4
- package/src/index.js +0 -117
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marko/compiler",
|
|
3
3
|
"description": "Marko template to JS compiler.",
|
|
4
|
-
"version": "5.21.
|
|
4
|
+
"version": "5.21.1",
|
|
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": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"@babel/runtime": "^7.16.0",
|
|
14
14
|
"@babel/traverse": "^7.16.0",
|
|
15
15
|
"@babel/types": "^7.16.0",
|
|
16
|
-
"@marko/babel-utils": "^5.21.
|
|
16
|
+
"@marko/babel-utils": "^5.21.1",
|
|
17
17
|
"complain": "^1.6.0",
|
|
18
18
|
"he": "^1.2.0",
|
|
19
19
|
"htmljs-parser": "^3.3.1",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"strip-json-comments": "^3.1.1"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@marko/translator-default": "^5.21.
|
|
31
|
+
"@marko/translator-default": "^5.21.1"
|
|
32
32
|
},
|
|
33
33
|
"files": [
|
|
34
34
|
"dist",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"plugin"
|
|
49
49
|
],
|
|
50
50
|
"license": "MIT",
|
|
51
|
-
"main": "
|
|
51
|
+
"main": "dist/index.js",
|
|
52
52
|
"main:dev": "src/index.js",
|
|
53
53
|
"main:npm": "dist/index.js",
|
|
54
54
|
"publishConfig": {
|
package/src/index.js
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
export * as types from "./babel-types";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import * as babel from "@babel/core";
|
|
4
|
-
import corePlugin from "./babel-plugin";
|
|
5
|
-
import defaultConfig from "./config";
|
|
6
|
-
import * as taglib from "./taglib";
|
|
7
|
-
import shouldOptimize from "./util/should-optimize";
|
|
8
|
-
import tryLoadTranslator from "./util/try-load-translator";
|
|
9
|
-
export { taglib };
|
|
10
|
-
|
|
11
|
-
let globalConfig = { ...defaultConfig };
|
|
12
|
-
export function configure(newConfig) {
|
|
13
|
-
globalConfig = { ...defaultConfig, ...newConfig };
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export async function compile(src, filename, config) {
|
|
17
|
-
const babelConfig = loadBabelConfig(filename, config);
|
|
18
|
-
const babelResult = await babel.transformAsync(src, babelConfig);
|
|
19
|
-
scheduleDefaultClear(config);
|
|
20
|
-
return buildResult(babelResult);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function compileSync(src, filename, config) {
|
|
24
|
-
const babelConfig = loadBabelConfig(filename, config);
|
|
25
|
-
const babelResult = babel.transformSync(src, babelConfig);
|
|
26
|
-
scheduleDefaultClear(config);
|
|
27
|
-
return buildResult(babelResult);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export async function compileFile(filename, config) {
|
|
31
|
-
return new Promise((resolve, reject) => {
|
|
32
|
-
getFs(config).readFile(filename, "utf-8", (err, src) => {
|
|
33
|
-
if (err) {
|
|
34
|
-
return reject(err);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return resolve(compile(src, filename, config));
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function compileFileSync(filename, config) {
|
|
43
|
-
const src = getFs(config).readFileSync(filename, "utf-8");
|
|
44
|
-
return compileSync(src, filename, config);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function getRuntimeEntryFiles(output, requestedTranslator) {
|
|
48
|
-
const translator = tryLoadTranslator(requestedTranslator);
|
|
49
|
-
if (translator && translator.getRuntimeEntryFiles) {
|
|
50
|
-
return translator.getRuntimeEntryFiles(output, shouldOptimize());
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return [];
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function loadBabelConfig(filename, config) {
|
|
57
|
-
const markoConfig = { ...globalConfig, ...config, babelConfig: undefined };
|
|
58
|
-
const requiredPlugins = [[corePlugin, markoConfig]];
|
|
59
|
-
const baseBabelConfig = {
|
|
60
|
-
filenameRelative: filename
|
|
61
|
-
? path.relative(process.cwd(), filename)
|
|
62
|
-
: undefined,
|
|
63
|
-
sourceFileName: filename ? path.basename(filename) : undefined,
|
|
64
|
-
...(config && config.babelConfig),
|
|
65
|
-
filename,
|
|
66
|
-
sourceType: "module",
|
|
67
|
-
sourceMaps: markoConfig.sourceMaps,
|
|
68
|
-
code: markoConfig.code,
|
|
69
|
-
ast: markoConfig.ast
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
if (markoConfig.modules === "cjs") {
|
|
73
|
-
requiredPlugins.push([
|
|
74
|
-
require.resolve("@babel/plugin-transform-modules-commonjs"),
|
|
75
|
-
{ loose: true }
|
|
76
|
-
]);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
baseBabelConfig.plugins = requiredPlugins.concat(
|
|
80
|
-
baseBabelConfig.plugins || []
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
return babel.loadPartialConfig(baseBabelConfig).options;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function buildResult(babelResult) {
|
|
87
|
-
const {
|
|
88
|
-
ast,
|
|
89
|
-
map,
|
|
90
|
-
code,
|
|
91
|
-
metadata: { marko: meta }
|
|
92
|
-
} = babelResult;
|
|
93
|
-
return { ast, map, code, meta };
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
let clearingDefaultCache = false;
|
|
97
|
-
function scheduleDefaultClear(config) {
|
|
98
|
-
if (
|
|
99
|
-
!clearingDefaultCache &&
|
|
100
|
-
(clearingDefaultCache = isDefaultCache(config))
|
|
101
|
-
) {
|
|
102
|
-
setImmediate(_clearDefaults);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export function _clearDefaults() {
|
|
107
|
-
clearingDefaultCache = false;
|
|
108
|
-
globalConfig.cache.clear();
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function isDefaultCache(config) {
|
|
112
|
-
return !config.cache || config.cache === globalConfig.cache;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function getFs(config) {
|
|
116
|
-
return config.fileSystem || globalConfig.fileSystem;
|
|
117
|
-
}
|