@marko/compiler 5.39.43 → 5.39.45
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/babel-utils.d.ts +20 -8
- package/dist/babel-plugin/index.js +11 -8
- package/dist/babel-plugin/parser.js +9 -3
- package/dist/babel-types/types/patch.js +1 -0
- package/dist/taglib/finder/index.js +42 -27
- package/dist/taglib/index.js +5 -1
- package/dist/taglib/loader/Taglib.js +1 -0
- package/dist/taglib/lookup/index.js +13 -0
- package/index.d.ts +1 -0
- package/package.json +2 -2
package/babel-utils.d.ts
CHANGED
|
@@ -23,6 +23,10 @@ export interface PluginDefinition<T = any> {
|
|
|
23
23
|
path?: string;
|
|
24
24
|
hook: Plugin<T>;
|
|
25
25
|
}
|
|
26
|
+
export interface ParsePluginDefinition<T = any> {
|
|
27
|
+
path?: string;
|
|
28
|
+
hook: ParsePlugin<T>;
|
|
29
|
+
}
|
|
26
30
|
export interface TagDefinition {
|
|
27
31
|
dir: string;
|
|
28
32
|
filePath: string;
|
|
@@ -57,7 +61,7 @@ export interface TagDefinition {
|
|
|
57
61
|
openTagOnly: boolean;
|
|
58
62
|
analyzer?: PluginDefinition<t.MarkoTag>;
|
|
59
63
|
translator?: PluginDefinition<t.MarkoTag>;
|
|
60
|
-
parser?:
|
|
64
|
+
parser?: ParsePluginDefinition<t.MarkoTag>;
|
|
61
65
|
transformers?: PluginDefinition<t.MarkoTag>[];
|
|
62
66
|
migrators?: PluginDefinition<t.MarkoTag>[];
|
|
63
67
|
parseOptions?: {
|
|
@@ -81,6 +85,8 @@ export interface TaglibLookup {
|
|
|
81
85
|
tagName: string,
|
|
82
86
|
callback: (attr: AttributeDefinition, tag: TagDefinition) => void,
|
|
83
87
|
): void;
|
|
88
|
+
exclusiveTagDiscoveryDirs: undefined | false | string;
|
|
89
|
+
manualTagsDirs: undefined | Set<string>;
|
|
84
90
|
}
|
|
85
91
|
|
|
86
92
|
export interface Attribute {
|
|
@@ -127,9 +133,9 @@ export interface Tag {
|
|
|
127
133
|
openTagOnly?: boolean;
|
|
128
134
|
analyze?: Plugin<t.MarkoTag>;
|
|
129
135
|
translate?: Plugin<t.MarkoTag>;
|
|
130
|
-
parse?:
|
|
131
|
-
transform?: Plugin<t.MarkoTag>[];
|
|
132
|
-
migrate?: Plugin<t.MarkoTag>[];
|
|
136
|
+
parse?: ParsePlugin<t.MarkoTag>;
|
|
137
|
+
transform?: Plugin<t.MarkoTag> | Plugin<t.MarkoTag>[];
|
|
138
|
+
migrate?: Plugin<t.MarkoTag> | Plugin<t.MarkoTag>[];
|
|
133
139
|
parseOptions?: {
|
|
134
140
|
rootOnly?: boolean;
|
|
135
141
|
rawOpenTag?: boolean;
|
|
@@ -147,14 +153,20 @@ export type FunctionPlugin<T = any> = (
|
|
|
147
153
|
path: t.NodePath<T>,
|
|
148
154
|
types: typeof t,
|
|
149
155
|
) => void;
|
|
150
|
-
export
|
|
156
|
+
export interface EnterExitPlugin<T = any> {
|
|
151
157
|
enter?(path: t.NodePath<T>, types: typeof t): void;
|
|
152
158
|
exit?(path: t.NodePath<T>, types: typeof t): void;
|
|
153
|
-
}
|
|
159
|
+
}
|
|
154
160
|
|
|
155
|
-
export
|
|
161
|
+
export interface ModulePlugin<T = any> {
|
|
156
162
|
default: EnterExitPlugin<T> | FunctionPlugin<T>;
|
|
157
|
-
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export interface ModuleFunctionPlugin<T = any> {
|
|
166
|
+
default: FunctionPlugin<T>;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export type ParsePlugin<T = any> = ModuleFunctionPlugin<T> | FunctionPlugin<T>;
|
|
158
170
|
|
|
159
171
|
export type Plugin<T = any> =
|
|
160
172
|
| ModulePlugin<T>
|
|
@@ -220,7 +220,8 @@ function getMarkoFile(code, fileOpts, markoOpts) {
|
|
|
220
220
|
deps: [],
|
|
221
221
|
tags: [],
|
|
222
222
|
watchFiles: [],
|
|
223
|
-
diagnostics: []
|
|
223
|
+
diagnostics: [],
|
|
224
|
+
api: translator.preferAPI
|
|
224
225
|
};
|
|
225
226
|
|
|
226
227
|
(0, _parser.parseMarko)(file);
|
|
@@ -273,14 +274,10 @@ function getMarkoFile(code, fileOpts, markoOpts) {
|
|
|
273
274
|
}
|
|
274
275
|
}
|
|
275
276
|
|
|
276
|
-
if (markoOpts.stripTypes) {
|
|
277
|
-
stripTypes(file);
|
|
278
|
-
if (!isMigrate) {
|
|
279
|
-
file.path.scope.crawl();
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
277
|
if (isMigrate) {
|
|
278
|
+
if (markoOpts.stripTypes) {
|
|
279
|
+
stripTypes(file);
|
|
280
|
+
}
|
|
284
281
|
return file;
|
|
285
282
|
}
|
|
286
283
|
|
|
@@ -299,6 +296,12 @@ function getMarkoFile(code, fileOpts, markoOpts) {
|
|
|
299
296
|
}
|
|
300
297
|
traverseAll(file, rootTransformers);
|
|
301
298
|
|
|
299
|
+
if (markoOpts.stripTypes) {
|
|
300
|
+
stripTypes(file);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
file.path.scope.crawl();
|
|
304
|
+
|
|
302
305
|
for (const taglibId in taglibLookup.taglibsById) {
|
|
303
306
|
const { filePath } = taglibLookup.taglibsById[taglibId];
|
|
304
307
|
|
|
@@ -18,6 +18,7 @@ var _mergeErrors = _interopRequireDefault(require("../util/merge-errors"));funct
|
|
|
18
18
|
const noop = () => {};
|
|
19
19
|
const emptyRange = (part) => part.start === part.end;
|
|
20
20
|
const isAttrTag = (tag) => tag.name.value?.[0] === "@";
|
|
21
|
+
const isStatementTag = (tag) => tag.tagDef?.parseOptions?.statement;
|
|
21
22
|
const toBabelPosition = ({ line, character }) => ({
|
|
22
23
|
// Babel lines start at 1 and use "column" instead of "character".
|
|
23
24
|
line: line + 1,
|
|
@@ -28,6 +29,7 @@ function parseMarko(file) {
|
|
|
28
29
|
const { code } = file;
|
|
29
30
|
const { htmlParseOptions = {} } = file.markoOpts;
|
|
30
31
|
const { watchFiles } = file.metadata.marko;
|
|
32
|
+
const parseVisits = [];
|
|
31
33
|
let currentTag = file.path;
|
|
32
34
|
let currentBody = currentTag;
|
|
33
35
|
let currentAttr = undefined;
|
|
@@ -183,7 +185,7 @@ function parseMarko(file) {
|
|
|
183
185
|
}
|
|
184
186
|
break;
|
|
185
187
|
case "MarkoTag":
|
|
186
|
-
if (isAttrTag(prev)) {
|
|
188
|
+
if (isStatementTag(prev) || isAttrTag(prev)) {
|
|
187
189
|
value = value.replace(/^[\n\r]\s*/, "");
|
|
188
190
|
}
|
|
189
191
|
break;
|
|
@@ -207,7 +209,7 @@ function parseMarko(file) {
|
|
|
207
209
|
}
|
|
208
210
|
break;
|
|
209
211
|
case "MarkoTag":
|
|
210
|
-
if (isAttrTag(next)) {
|
|
212
|
+
if (isStatementTag(next) || isAttrTag(next)) {
|
|
211
213
|
value = value.replace(/[\n\r]\s*$/, "");
|
|
212
214
|
}
|
|
213
215
|
|
|
@@ -558,7 +560,7 @@ function parseMarko(file) {
|
|
|
558
560
|
if (parserPlugin) {
|
|
559
561
|
const { hook } = parserPlugin;
|
|
560
562
|
if (parserPlugin.path) watchFiles.push(parserPlugin.path);
|
|
561
|
-
(hook.default || hook
|
|
563
|
+
parseVisits.push(hook.default || hook, currentTag);
|
|
562
564
|
}
|
|
563
565
|
|
|
564
566
|
const parentTag = isAttrTag(node) ?
|
|
@@ -637,6 +639,10 @@ function parseMarko(file) {
|
|
|
637
639
|
parser.parse(code);
|
|
638
640
|
onNext();
|
|
639
641
|
|
|
642
|
+
for (let i = 0; i < parseVisits.length;) {
|
|
643
|
+
parseVisits[i++](parseVisits[i++]);
|
|
644
|
+
}
|
|
645
|
+
|
|
640
646
|
const { ast } = file;
|
|
641
647
|
const { program } = ast;
|
|
642
648
|
ast.start = program.start = 0;
|
|
@@ -19,6 +19,7 @@ const {
|
|
|
19
19
|
getBindingIdentifiers.keys.Program = ["params"];
|
|
20
20
|
getBindingIdentifiers.keys.MarkoTag = ["var"];
|
|
21
21
|
getBindingIdentifiers.keys.MarkoTagBody = ["params"];
|
|
22
|
+
getBindingIdentifiers.keys.MarkoScriptlet = ["body"];
|
|
22
23
|
|
|
23
24
|
_definitions.MARKO_TYPES.forEach((typeName) => {
|
|
24
25
|
definitionUtils.default(typeName, _definitions.default[typeName]);
|
|
@@ -51,27 +51,13 @@ function getAllDependencyNames(pkg) {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
function find(dirname, registeredTaglibs, tagDiscoveryDirs) {
|
|
54
|
-
var
|
|
55
|
-
if (
|
|
56
|
-
return
|
|
54
|
+
var cached = findCache[dirname];
|
|
55
|
+
if (cached) {
|
|
56
|
+
return cached.taglibs;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
var added = {};
|
|
62
|
-
|
|
63
|
-
var helper = {
|
|
64
|
-
addTaglib: function (taglib) {
|
|
65
|
-
if (added[taglib.id]) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
added[taglib.id] = true;
|
|
70
|
-
found.push(taglib);
|
|
71
|
-
},
|
|
72
|
-
foundTaglibPackages: {}
|
|
73
|
-
};
|
|
74
|
-
|
|
59
|
+
var taglibs = [];
|
|
60
|
+
var added = new Set();
|
|
75
61
|
var rootDirname = markoModules.cwd; // Don't search up past this directory
|
|
76
62
|
var rootPkg = getModuleRootPackage(dirname);
|
|
77
63
|
if (rootPkg) {
|
|
@@ -80,27 +66,41 @@ function find(dirname, registeredTaglibs, tagDiscoveryDirs) {
|
|
|
80
66
|
|
|
81
67
|
// First walk up the directory tree looking for marko.json files or components/ directories
|
|
82
68
|
let curDirname = dirname;
|
|
69
|
+
// exclusiveTagDiscoveryDirs is used for the interop to detect if `tags` directories are used exclusively when finding tags
|
|
70
|
+
let exclusiveTagDiscoveryDirs = undefined;
|
|
83
71
|
|
|
84
72
|
while (true) {
|
|
85
73
|
if (!excludedDirs[curDirname]) {
|
|
86
74
|
let taglibPath = nodePath.join(curDirname, "marko.json");
|
|
87
75
|
let taglib;
|
|
76
|
+
let manualTagsDir;
|
|
88
77
|
|
|
89
78
|
if (existsSync(taglibPath)) {
|
|
90
79
|
taglib = taglibLoader.loadTaglibFromFile(taglibPath);
|
|
91
|
-
|
|
80
|
+
manualTagsDir = taglib.tagsDir;
|
|
81
|
+
addTaglib(taglib);
|
|
92
82
|
}
|
|
93
83
|
|
|
94
|
-
if (
|
|
84
|
+
if (manualTagsDir === undefined) {
|
|
95
85
|
for (const tagDiscoveryDir of tagDiscoveryDirs) {
|
|
96
86
|
const componentsPath = nodePath.join(curDirname, tagDiscoveryDir);
|
|
97
87
|
|
|
98
88
|
if (existsSync(componentsPath) && !excludedDirs[componentsPath]) {
|
|
99
|
-
|
|
89
|
+
if (exclusiveTagDiscoveryDirs !== false) {
|
|
90
|
+
if (exclusiveTagDiscoveryDirs === undefined) {
|
|
91
|
+
exclusiveTagDiscoveryDirs = tagDiscoveryDir;
|
|
92
|
+
} else if (exclusiveTagDiscoveryDirs !== tagDiscoveryDir) {
|
|
93
|
+
exclusiveTagDiscoveryDirs = false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
addTaglib(
|
|
100
98
|
taglibLoader.loadTaglibFromDir(curDirname, tagDiscoveryDir)
|
|
101
99
|
);
|
|
102
100
|
}
|
|
103
101
|
}
|
|
102
|
+
} else if (manualTagsDir) {
|
|
103
|
+
exclusiveTagDiscoveryDirs = false;
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
|
|
@@ -120,26 +120,41 @@ function find(dirname, registeredTaglibs, tagDiscoveryDirs) {
|
|
|
120
120
|
getAllDependencyNames(rootPkg).forEach((name) => {
|
|
121
121
|
if (!excludedPackages[name]) {
|
|
122
122
|
let taglibPath = markoModules.tryResolve(
|
|
123
|
-
|
|
123
|
+
name + "/marko.json",
|
|
124
124
|
rootPkg.__dirname
|
|
125
125
|
);
|
|
126
126
|
if (taglibPath) {
|
|
127
127
|
var taglib = taglibLoader.loadTaglibFromFile(taglibPath, true);
|
|
128
|
-
|
|
128
|
+
addTaglib(taglib);
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
});
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
for (let i = registeredTaglibs.length; i--;) {
|
|
135
|
-
|
|
135
|
+
addTaglib(registeredTaglibs[i]);
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
findCache[dirname] =
|
|
138
|
+
findCache[dirname] = { exclusiveTagDiscoveryDirs, taglibs };
|
|
139
|
+
return taglibs;
|
|
139
140
|
|
|
140
|
-
|
|
141
|
+
function addTaglib(taglib) {
|
|
142
|
+
if (!added.has(taglib.id)) {
|
|
143
|
+
added.add(taglib.id);
|
|
144
|
+
taglibs.push(taglib);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
141
147
|
}
|
|
142
148
|
|
|
149
|
+
find._withMeta = function findWithMeta(
|
|
150
|
+
dirname,
|
|
151
|
+
registeredTaglibs,
|
|
152
|
+
tagDiscoveryDirs)
|
|
153
|
+
{
|
|
154
|
+
find(dirname, registeredTaglibs, tagDiscoveryDirs);
|
|
155
|
+
return findCache[dirname];
|
|
156
|
+
};
|
|
157
|
+
|
|
143
158
|
function clearCache() {
|
|
144
159
|
findCache = {};
|
|
145
160
|
}
|
package/dist/taglib/index.js
CHANGED
|
@@ -32,6 +32,7 @@ function buildLookup(dirname, requestedTranslator, onError) {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
let taglibsForDir = loadedTranslatorsTaglibs.get(translator);
|
|
35
|
+
let exclusiveTagDiscoveryDirs = undefined;
|
|
35
36
|
|
|
36
37
|
if (!taglibsForDir) {
|
|
37
38
|
loadedTranslatorsTaglibs.set(
|
|
@@ -45,11 +46,13 @@ function buildLookup(dirname, requestedTranslator, onError) {
|
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
runAndCatchErrors(() => {
|
|
48
|
-
|
|
49
|
+
const foundMeta = _finder2.default.find._withMeta(
|
|
49
50
|
dirname,
|
|
50
51
|
taglibsForDir,
|
|
51
52
|
translator.tagDiscoveryDirs
|
|
52
53
|
);
|
|
54
|
+
taglibsForDir = foundMeta.taglibs;
|
|
55
|
+
exclusiveTagDiscoveryDirs = foundMeta.exclusiveTagDiscoveryDirs;
|
|
53
56
|
}, onError);
|
|
54
57
|
|
|
55
58
|
const cacheKey = taglibsForDir.
|
|
@@ -60,6 +63,7 @@ function buildLookup(dirname, requestedTranslator, onError) {
|
|
|
60
63
|
|
|
61
64
|
if (!lookup) {
|
|
62
65
|
lookup = lookupCache[cacheKey] = new _lookup.default();
|
|
66
|
+
lookup.exclusiveTagDiscoveryDirs = exclusiveTagDiscoveryDirs;
|
|
63
67
|
for (let i = taglibsForDir.length; i--;) {
|
|
64
68
|
const taglib = taglibsForDir[i];
|
|
65
69
|
lookup.addTaglib(taglib);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var nodePath = require("path");
|
|
3
4
|
var ok = require("assert").ok;
|
|
4
5
|
var extend = require("raptor-util/extend");
|
|
5
6
|
var taglibTypes = require("../loader/types");
|
|
@@ -51,6 +52,8 @@ class TaglibLookup {
|
|
|
51
52
|
this.taglibsById = {};
|
|
52
53
|
|
|
53
54
|
this._sortedTags = undefined;
|
|
55
|
+
this.exclusiveTagDiscoveryDirs = undefined;
|
|
56
|
+
this.manualTagsDirs = undefined;
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
hasTaglib(taglib) {
|
|
@@ -96,6 +99,16 @@ class TaglibLookup {
|
|
|
96
99
|
return;
|
|
97
100
|
}
|
|
98
101
|
|
|
102
|
+
if (
|
|
103
|
+
taglib.dirname &&
|
|
104
|
+
typeof taglib.tagsDir === "string" &&
|
|
105
|
+
/[/\\]tags[/\\]?$/.test(taglib.tagsDir))
|
|
106
|
+
{
|
|
107
|
+
(this.manualTagsDirs || (this.manualTagsDirs = new Set())).add(
|
|
108
|
+
nodePath.resolve(taglib.dirname, taglib.tagsDir)
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
99
112
|
// console.log("TAGLIB:", taglib);
|
|
100
113
|
|
|
101
114
|
this._sortedTags = undefined;
|
package/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marko/compiler",
|
|
3
|
-
"version": "5.39.
|
|
3
|
+
"version": "5.39.45",
|
|
4
4
|
"description": "Marko template to JS compiler.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"babel",
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"source-map-support": "^0.5.21"
|
|
88
88
|
},
|
|
89
89
|
"devDependencies": {
|
|
90
|
-
"marko": "^5.
|
|
90
|
+
"marko": "^5.38.1"
|
|
91
91
|
},
|
|
92
92
|
"engines": {
|
|
93
93
|
"node": "18 || 20 || >=22"
|