@marko/language-tools 2.5.59 → 2.5.60
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/index.d.ts +1 -0
- package/dist/index.js +27 -20
- package/dist/index.mjs +26 -20
- package/dist/util/normalize-path.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -6,4 +6,5 @@ export * as Processors from "./processors";
|
|
|
6
6
|
export { type Extracted } from "./util/extractor";
|
|
7
7
|
export { getExt } from "./util/get-ext";
|
|
8
8
|
export { isDefinitionFile } from "./util/is-definition-file";
|
|
9
|
+
export { normalizePath } from "./util/normalize-path";
|
|
9
10
|
export * as Project from "./util/project";
|
package/dist/index.js
CHANGED
|
@@ -44,6 +44,7 @@ __export(index_exports, {
|
|
|
44
44
|
getPosition: () => import_htmljs_parser2.getPosition,
|
|
45
45
|
isControlFlowTag: () => isControlFlowTag,
|
|
46
46
|
isDefinitionFile: () => isDefinitionFile,
|
|
47
|
+
normalizePath: () => normalizePath,
|
|
47
48
|
parse: () => parse
|
|
48
49
|
});
|
|
49
50
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -132,6 +133,11 @@ function childAtOffset(offset, children) {
|
|
|
132
133
|
return offset > child.start && offset <= child.end ? child : void 0;
|
|
133
134
|
}
|
|
134
135
|
|
|
136
|
+
// src/util/normalize-path.ts
|
|
137
|
+
var import_path = __toESM(require("path"));
|
|
138
|
+
var sepReg = /\//g;
|
|
139
|
+
var normalizePath = import_path.default.sep === "/" ? (filename) => filename : (filename) => filename.replace(sepReg, import_path.default.sep);
|
|
140
|
+
|
|
135
141
|
// src/parser.ts
|
|
136
142
|
var import_htmljs_parser2 = require("htmljs-parser");
|
|
137
143
|
var styleBlockReg = /((?:\.[^\s\\/:*?"<>|({]+)*)\s*\{/y;
|
|
@@ -178,7 +184,7 @@ function parse(code, filename = "index.marko") {
|
|
|
178
184
|
locationAt: parser.locationAt,
|
|
179
185
|
positionAt: parser.positionAt,
|
|
180
186
|
nodeAt: (offset) => getNodeAtOffset(offset, program),
|
|
181
|
-
filename,
|
|
187
|
+
filename: normalizePath(filename),
|
|
182
188
|
program,
|
|
183
189
|
code
|
|
184
190
|
};
|
|
@@ -1816,10 +1822,10 @@ function byStart(a, b) {
|
|
|
1816
1822
|
|
|
1817
1823
|
// src/extractors/script/util/get-component-filename.ts
|
|
1818
1824
|
var import_fs = __toESM(require("fs"));
|
|
1819
|
-
var
|
|
1825
|
+
var import_path2 = __toESM(require("path"));
|
|
1820
1826
|
function getComponentFilename(from) {
|
|
1821
|
-
const dir =
|
|
1822
|
-
let nameNoExt =
|
|
1827
|
+
const dir = import_path2.default.dirname(from);
|
|
1828
|
+
let nameNoExt = import_path2.default.basename(from, ".marko");
|
|
1823
1829
|
if (nameNoExt.endsWith(".d")) {
|
|
1824
1830
|
nameNoExt = nameNoExt.slice(0, -2);
|
|
1825
1831
|
}
|
|
@@ -1830,7 +1836,7 @@ function getComponentFilename(from) {
|
|
|
1830
1836
|
);
|
|
1831
1837
|
for (const entry of tryReaddirSync(dir)) {
|
|
1832
1838
|
if (componentMatch.test(entry)) {
|
|
1833
|
-
return
|
|
1839
|
+
return import_path2.default.join(dir, entry);
|
|
1834
1840
|
}
|
|
1835
1841
|
}
|
|
1836
1842
|
}
|
|
@@ -3461,17 +3467,17 @@ ${isMutatedVar(tag.parent, valueLiteral) ? varLocal(`change__${valueLiteral}.`)
|
|
|
3461
3467
|
return ((_a = this.#lookup.getTag(nameText)) == null ? void 0 : _a.targetProperty) || nameText.slice(nameText.lastIndexOf(":") + 1);
|
|
3462
3468
|
}
|
|
3463
3469
|
#getAttrTagPath(tag) {
|
|
3464
|
-
let
|
|
3470
|
+
let path5 = `"${this.#getAttrTagName(tag)}"`;
|
|
3465
3471
|
let curTag = tag.parent;
|
|
3466
3472
|
while (curTag) {
|
|
3467
3473
|
if (curTag.type === 16 /* AttrTag */) {
|
|
3468
|
-
|
|
3474
|
+
path5 = `"${this.#getAttrTagName(curTag)}",${path5}`;
|
|
3469
3475
|
} else if (!isControlFlowTag(curTag)) {
|
|
3470
3476
|
break;
|
|
3471
3477
|
}
|
|
3472
3478
|
curTag = curTag.parent;
|
|
3473
3479
|
}
|
|
3474
|
-
return
|
|
3480
|
+
return path5;
|
|
3475
3481
|
}
|
|
3476
3482
|
#getTagInputType(tag) {
|
|
3477
3483
|
if (tag.type === 16 /* AttrTag */) {
|
|
@@ -3607,7 +3613,7 @@ function isValueAttribute(attr) {
|
|
|
3607
3613
|
function resolveTagImport(from, def) {
|
|
3608
3614
|
const filename = resolveTagFile(def);
|
|
3609
3615
|
if (filename) {
|
|
3610
|
-
return from ? (0, import_relative_import_path.relativeImportPath)(from, filename) : filename;
|
|
3616
|
+
return from ? (0, import_relative_import_path.relativeImportPath)(from, normalizePath(filename)) : filename;
|
|
3611
3617
|
}
|
|
3612
3618
|
}
|
|
3613
3619
|
function resolveTagFile(def) {
|
|
@@ -3718,7 +3724,7 @@ function getExt(fileName) {
|
|
|
3718
3724
|
}
|
|
3719
3725
|
|
|
3720
3726
|
// src/processors/marko.ts
|
|
3721
|
-
var
|
|
3727
|
+
var import_path4 = __toESM(require("path"));
|
|
3722
3728
|
|
|
3723
3729
|
// src/util/project.ts
|
|
3724
3730
|
var project_exports = {};
|
|
@@ -3735,7 +3741,7 @@ __export(project_exports, {
|
|
|
3735
3741
|
});
|
|
3736
3742
|
var import_strip_json_comments = require("@luxass/strip-json-comments");
|
|
3737
3743
|
var import_module = require("module");
|
|
3738
|
-
var
|
|
3744
|
+
var import_path3 = __toESM(require("path"));
|
|
3739
3745
|
var defaultTypeLibs = {};
|
|
3740
3746
|
var defaultMeta;
|
|
3741
3747
|
var ignoreErrors = (_err) => {
|
|
@@ -3762,11 +3768,11 @@ function getTypeLibs(rootDir, ts, host) {
|
|
|
3762
3768
|
const resolveTypeCompilerOptions = {
|
|
3763
3769
|
moduleResolution: ts.ModuleResolutionKind.Bundler
|
|
3764
3770
|
};
|
|
3765
|
-
const markoRunGeneratedTypesFile =
|
|
3771
|
+
const markoRunGeneratedTypesFile = import_path3.default.join(
|
|
3766
3772
|
rootDir,
|
|
3767
3773
|
".marko-run/routes.d.ts"
|
|
3768
3774
|
);
|
|
3769
|
-
const resolveFromFile =
|
|
3775
|
+
const resolveFromFile = import_path3.default.join(rootDir, "_.d.ts");
|
|
3770
3776
|
const internalTypesFile = defaultTypeLibs.internalTypesFile || ((_a = ts.resolveTypeReferenceDirective(
|
|
3771
3777
|
"@marko/language-tools/marko.internal.d.ts",
|
|
3772
3778
|
resolveFromFile,
|
|
@@ -3804,7 +3810,7 @@ function getTypeLibs(rootDir, ts, host) {
|
|
|
3804
3810
|
}
|
|
3805
3811
|
function getScriptLang(fileName, defaultScriptLang, ts, host) {
|
|
3806
3812
|
if (fileName.endsWith(".d.marko")) return "ts" /* ts */;
|
|
3807
|
-
const dir =
|
|
3813
|
+
const dir = import_path3.default.dirname(fileName);
|
|
3808
3814
|
const config = getConfig(dir);
|
|
3809
3815
|
const cache = config.cache.get(getScriptLang);
|
|
3810
3816
|
let scriptLang = cache == null ? void 0 : cache.get(dir);
|
|
@@ -3888,7 +3894,7 @@ function getMeta(dir) {
|
|
|
3888
3894
|
function loadMeta(dir) {
|
|
3889
3895
|
let cached = metaByDir.get(dir);
|
|
3890
3896
|
if (!cached) {
|
|
3891
|
-
const require2 = (0, import_module.createRequire)(
|
|
3897
|
+
const require2 = (0, import_module.createRequire)(import_path3.default.join(dir, "_.js"));
|
|
3892
3898
|
const configPath = (() => {
|
|
3893
3899
|
try {
|
|
3894
3900
|
return require2.resolve("@marko/compiler/config");
|
|
@@ -3902,7 +3908,7 @@ function loadMeta(dir) {
|
|
|
3902
3908
|
const translatorPath = require2.resolve(config.translator);
|
|
3903
3909
|
cached = metaByTranslator.get(translatorPath);
|
|
3904
3910
|
if (!cached) {
|
|
3905
|
-
const compiler = require2(
|
|
3911
|
+
const compiler = require2(import_path3.default.dirname(configPath));
|
|
3906
3912
|
cached = {
|
|
3907
3913
|
compiler,
|
|
3908
3914
|
config: {
|
|
@@ -3963,13 +3969,13 @@ var marko_default = {
|
|
|
3963
3969
|
extension: ".marko",
|
|
3964
3970
|
create({ ts, host, configFile }) {
|
|
3965
3971
|
const currentDirectory = host.getCurrentDirectory ? host.getCurrentDirectory() : ts.sys.getCurrentDirectory();
|
|
3966
|
-
const defaultScriptLang = configFile && /tsconfig
|
|
3972
|
+
const defaultScriptLang = configFile && /tsconfig/.test(configFile) ? "ts" /* ts */ : "js" /* js */;
|
|
3967
3973
|
const runtimeTypes = getTypeLibs(currentDirectory, ts, host);
|
|
3968
3974
|
const rootNames = [
|
|
3969
3975
|
runtimeTypes.internalTypesFile,
|
|
3970
3976
|
runtimeTypes.markoTypesFile
|
|
3971
3977
|
];
|
|
3972
|
-
const getJSFileIfTSExists = (source, importer) => host.fileExists(
|
|
3978
|
+
const getJSFileIfTSExists = (source, importer) => host.fileExists(import_path4.default.join(importer, "..", `${source}.ts`)) && `${source}.js`;
|
|
3973
3979
|
const compileConfig = {
|
|
3974
3980
|
output: "source",
|
|
3975
3981
|
stripTypes: true,
|
|
@@ -4025,8 +4031,8 @@ var marko_default = {
|
|
|
4025
4031
|
return getScriptLang(fileName, defaultScriptLang, ts, host) === "ts" /* ts */ ? ts.ScriptKind.TS : ts.ScriptKind.JS;
|
|
4026
4032
|
},
|
|
4027
4033
|
extract(fileName, code) {
|
|
4028
|
-
const dir = import_path3.default.dirname(fileName);
|
|
4029
4034
|
const parsed = parse(code, fileName);
|
|
4035
|
+
const dir = import_path4.default.dirname(parsed.filename);
|
|
4030
4036
|
return extractScript({
|
|
4031
4037
|
ts,
|
|
4032
4038
|
parsed,
|
|
@@ -4043,7 +4049,7 @@ var marko_default = {
|
|
|
4043
4049
|
},
|
|
4044
4050
|
print({ extracted: { parsed } }) {
|
|
4045
4051
|
const { code, map } = getCompiler(
|
|
4046
|
-
|
|
4052
|
+
import_path4.default.dirname(parsed.filename)
|
|
4047
4053
|
).compileSync(parsed.code, parsed.filename, compileConfig);
|
|
4048
4054
|
return { code, map };
|
|
4049
4055
|
},
|
|
@@ -4188,5 +4194,6 @@ function isDefinitionFile(fileName) {
|
|
|
4188
4194
|
getPosition,
|
|
4189
4195
|
isControlFlowTag,
|
|
4190
4196
|
isDefinitionFile,
|
|
4197
|
+
normalizePath,
|
|
4191
4198
|
parse
|
|
4192
4199
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -88,6 +88,11 @@ function childAtOffset(offset, children) {
|
|
|
88
88
|
return offset > child.start && offset <= child.end ? child : void 0;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
// src/util/normalize-path.ts
|
|
92
|
+
import path from "path";
|
|
93
|
+
var sepReg = /\//g;
|
|
94
|
+
var normalizePath = path.sep === "/" ? (filename) => filename : (filename) => filename.replace(sepReg, path.sep);
|
|
95
|
+
|
|
91
96
|
// src/parser.ts
|
|
92
97
|
import {
|
|
93
98
|
getLines,
|
|
@@ -138,7 +143,7 @@ function parse(code, filename = "index.marko") {
|
|
|
138
143
|
locationAt: parser.locationAt,
|
|
139
144
|
positionAt: parser.positionAt,
|
|
140
145
|
nodeAt: (offset) => getNodeAtOffset(offset, program),
|
|
141
|
-
filename,
|
|
146
|
+
filename: normalizePath(filename),
|
|
142
147
|
program,
|
|
143
148
|
code
|
|
144
149
|
};
|
|
@@ -1779,10 +1784,10 @@ function byStart(a, b) {
|
|
|
1779
1784
|
|
|
1780
1785
|
// src/extractors/script/util/get-component-filename.ts
|
|
1781
1786
|
import fs from "fs";
|
|
1782
|
-
import
|
|
1787
|
+
import path2 from "path";
|
|
1783
1788
|
function getComponentFilename(from) {
|
|
1784
|
-
const dir =
|
|
1785
|
-
let nameNoExt =
|
|
1789
|
+
const dir = path2.dirname(from);
|
|
1790
|
+
let nameNoExt = path2.basename(from, ".marko");
|
|
1786
1791
|
if (nameNoExt.endsWith(".d")) {
|
|
1787
1792
|
nameNoExt = nameNoExt.slice(0, -2);
|
|
1788
1793
|
}
|
|
@@ -1793,7 +1798,7 @@ function getComponentFilename(from) {
|
|
|
1793
1798
|
);
|
|
1794
1799
|
for (const entry of tryReaddirSync(dir)) {
|
|
1795
1800
|
if (componentMatch.test(entry)) {
|
|
1796
|
-
return
|
|
1801
|
+
return path2.join(dir, entry);
|
|
1797
1802
|
}
|
|
1798
1803
|
}
|
|
1799
1804
|
}
|
|
@@ -3424,17 +3429,17 @@ ${isMutatedVar(tag.parent, valueLiteral) ? varLocal(`change__${valueLiteral}.`)
|
|
|
3424
3429
|
return ((_a = this.#lookup.getTag(nameText)) == null ? void 0 : _a.targetProperty) || nameText.slice(nameText.lastIndexOf(":") + 1);
|
|
3425
3430
|
}
|
|
3426
3431
|
#getAttrTagPath(tag) {
|
|
3427
|
-
let
|
|
3432
|
+
let path5 = `"${this.#getAttrTagName(tag)}"`;
|
|
3428
3433
|
let curTag = tag.parent;
|
|
3429
3434
|
while (curTag) {
|
|
3430
3435
|
if (curTag.type === 16 /* AttrTag */) {
|
|
3431
|
-
|
|
3436
|
+
path5 = `"${this.#getAttrTagName(curTag)}",${path5}`;
|
|
3432
3437
|
} else if (!isControlFlowTag(curTag)) {
|
|
3433
3438
|
break;
|
|
3434
3439
|
}
|
|
3435
3440
|
curTag = curTag.parent;
|
|
3436
3441
|
}
|
|
3437
|
-
return
|
|
3442
|
+
return path5;
|
|
3438
3443
|
}
|
|
3439
3444
|
#getTagInputType(tag) {
|
|
3440
3445
|
if (tag.type === 16 /* AttrTag */) {
|
|
@@ -3570,7 +3575,7 @@ function isValueAttribute(attr) {
|
|
|
3570
3575
|
function resolveTagImport(from, def) {
|
|
3571
3576
|
const filename = resolveTagFile(def);
|
|
3572
3577
|
if (filename) {
|
|
3573
|
-
return from ? relativeImportPath(from, filename) : filename;
|
|
3578
|
+
return from ? relativeImportPath(from, normalizePath(filename)) : filename;
|
|
3574
3579
|
}
|
|
3575
3580
|
}
|
|
3576
3581
|
function resolveTagFile(def) {
|
|
@@ -3681,7 +3686,7 @@ function getExt(fileName) {
|
|
|
3681
3686
|
}
|
|
3682
3687
|
|
|
3683
3688
|
// src/processors/marko.ts
|
|
3684
|
-
import
|
|
3689
|
+
import path4 from "path";
|
|
3685
3690
|
|
|
3686
3691
|
// src/util/project.ts
|
|
3687
3692
|
var project_exports = {};
|
|
@@ -3698,7 +3703,7 @@ __export(project_exports, {
|
|
|
3698
3703
|
});
|
|
3699
3704
|
import { strip as stripJSONComments } from "@luxass/strip-json-comments";
|
|
3700
3705
|
import { createRequire } from "module";
|
|
3701
|
-
import
|
|
3706
|
+
import path3 from "path";
|
|
3702
3707
|
var defaultTypeLibs = {};
|
|
3703
3708
|
var defaultMeta;
|
|
3704
3709
|
var ignoreErrors = (_err) => {
|
|
@@ -3725,11 +3730,11 @@ function getTypeLibs(rootDir, ts, host) {
|
|
|
3725
3730
|
const resolveTypeCompilerOptions = {
|
|
3726
3731
|
moduleResolution: ts.ModuleResolutionKind.Bundler
|
|
3727
3732
|
};
|
|
3728
|
-
const markoRunGeneratedTypesFile =
|
|
3733
|
+
const markoRunGeneratedTypesFile = path3.join(
|
|
3729
3734
|
rootDir,
|
|
3730
3735
|
".marko-run/routes.d.ts"
|
|
3731
3736
|
);
|
|
3732
|
-
const resolveFromFile =
|
|
3737
|
+
const resolveFromFile = path3.join(rootDir, "_.d.ts");
|
|
3733
3738
|
const internalTypesFile = defaultTypeLibs.internalTypesFile || ((_a = ts.resolveTypeReferenceDirective(
|
|
3734
3739
|
"@marko/language-tools/marko.internal.d.ts",
|
|
3735
3740
|
resolveFromFile,
|
|
@@ -3767,7 +3772,7 @@ function getTypeLibs(rootDir, ts, host) {
|
|
|
3767
3772
|
}
|
|
3768
3773
|
function getScriptLang(fileName, defaultScriptLang, ts, host) {
|
|
3769
3774
|
if (fileName.endsWith(".d.marko")) return "ts" /* ts */;
|
|
3770
|
-
const dir =
|
|
3775
|
+
const dir = path3.dirname(fileName);
|
|
3771
3776
|
const config = getConfig(dir);
|
|
3772
3777
|
const cache = config.cache.get(getScriptLang);
|
|
3773
3778
|
let scriptLang = cache == null ? void 0 : cache.get(dir);
|
|
@@ -3851,7 +3856,7 @@ function getMeta(dir) {
|
|
|
3851
3856
|
function loadMeta(dir) {
|
|
3852
3857
|
let cached = metaByDir.get(dir);
|
|
3853
3858
|
if (!cached) {
|
|
3854
|
-
const require2 = createRequire(
|
|
3859
|
+
const require2 = createRequire(path3.join(dir, "_.js"));
|
|
3855
3860
|
const configPath = (() => {
|
|
3856
3861
|
try {
|
|
3857
3862
|
return require2.resolve("@marko/compiler/config");
|
|
@@ -3865,7 +3870,7 @@ function loadMeta(dir) {
|
|
|
3865
3870
|
const translatorPath = require2.resolve(config.translator);
|
|
3866
3871
|
cached = metaByTranslator.get(translatorPath);
|
|
3867
3872
|
if (!cached) {
|
|
3868
|
-
const compiler = require2(
|
|
3873
|
+
const compiler = require2(path3.dirname(configPath));
|
|
3869
3874
|
cached = {
|
|
3870
3875
|
compiler,
|
|
3871
3876
|
config: {
|
|
@@ -3926,13 +3931,13 @@ var marko_default = {
|
|
|
3926
3931
|
extension: ".marko",
|
|
3927
3932
|
create({ ts, host, configFile }) {
|
|
3928
3933
|
const currentDirectory = host.getCurrentDirectory ? host.getCurrentDirectory() : ts.sys.getCurrentDirectory();
|
|
3929
|
-
const defaultScriptLang = configFile && /tsconfig
|
|
3934
|
+
const defaultScriptLang = configFile && /tsconfig/.test(configFile) ? "ts" /* ts */ : "js" /* js */;
|
|
3930
3935
|
const runtimeTypes = getTypeLibs(currentDirectory, ts, host);
|
|
3931
3936
|
const rootNames = [
|
|
3932
3937
|
runtimeTypes.internalTypesFile,
|
|
3933
3938
|
runtimeTypes.markoTypesFile
|
|
3934
3939
|
];
|
|
3935
|
-
const getJSFileIfTSExists = (source, importer) => host.fileExists(
|
|
3940
|
+
const getJSFileIfTSExists = (source, importer) => host.fileExists(path4.join(importer, "..", `${source}.ts`)) && `${source}.js`;
|
|
3936
3941
|
const compileConfig = {
|
|
3937
3942
|
output: "source",
|
|
3938
3943
|
stripTypes: true,
|
|
@@ -3988,8 +3993,8 @@ var marko_default = {
|
|
|
3988
3993
|
return getScriptLang(fileName, defaultScriptLang, ts, host) === "ts" /* ts */ ? ts.ScriptKind.TS : ts.ScriptKind.JS;
|
|
3989
3994
|
},
|
|
3990
3995
|
extract(fileName, code) {
|
|
3991
|
-
const dir = path3.dirname(fileName);
|
|
3992
3996
|
const parsed = parse(code, fileName);
|
|
3997
|
+
const dir = path4.dirname(parsed.filename);
|
|
3993
3998
|
return extractScript({
|
|
3994
3999
|
ts,
|
|
3995
4000
|
parsed,
|
|
@@ -4006,7 +4011,7 @@ var marko_default = {
|
|
|
4006
4011
|
},
|
|
4007
4012
|
print({ extracted: { parsed } }) {
|
|
4008
4013
|
const { code, map } = getCompiler(
|
|
4009
|
-
|
|
4014
|
+
path4.dirname(parsed.filename)
|
|
4010
4015
|
).compileSync(parsed.code, parsed.filename, compileConfig);
|
|
4011
4016
|
return { code, map };
|
|
4012
4017
|
},
|
|
@@ -4150,5 +4155,6 @@ export {
|
|
|
4150
4155
|
getPosition,
|
|
4151
4156
|
isControlFlowTag,
|
|
4152
4157
|
isDefinitionFile,
|
|
4158
|
+
normalizePath,
|
|
4153
4159
|
parse
|
|
4154
4160
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const normalizePath: (filename: string) => string;
|