@marko/language-tools 2.5.59 → 2.5.61

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 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 import_path = __toESM(require("path"));
1825
+ var import_path2 = __toESM(require("path"));
1820
1826
  function getComponentFilename(from) {
1821
- const dir = import_path.default.dirname(from);
1822
- let nameNoExt = import_path.default.basename(from, ".marko");
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 import_path.default.join(dir, entry);
1839
+ return import_path2.default.join(dir, entry);
1834
1840
  }
1835
1841
  }
1836
1842
  }
@@ -3364,6 +3370,15 @@ ${isMutatedVar(tag.parent, valueLiteral) ? varLocal(`change__${valueLiteral}.`)
3364
3370
  })
3365
3371
  };
3366
3372
  }
3373
+ } else if (node.type === 24 /* Import */) {
3374
+ const imported = this.#ast.import(node);
3375
+ if (imported) {
3376
+ for (const specifier of imported.specifiers) {
3377
+ if (specifier.local.name === "Input") {
3378
+ return { typeParameters: void 0 };
3379
+ }
3380
+ }
3381
+ }
3367
3382
  }
3368
3383
  }
3369
3384
  }
@@ -3461,17 +3476,17 @@ ${isMutatedVar(tag.parent, valueLiteral) ? varLocal(`change__${valueLiteral}.`)
3461
3476
  return ((_a = this.#lookup.getTag(nameText)) == null ? void 0 : _a.targetProperty) || nameText.slice(nameText.lastIndexOf(":") + 1);
3462
3477
  }
3463
3478
  #getAttrTagPath(tag) {
3464
- let path4 = `"${this.#getAttrTagName(tag)}"`;
3479
+ let path5 = `"${this.#getAttrTagName(tag)}"`;
3465
3480
  let curTag = tag.parent;
3466
3481
  while (curTag) {
3467
3482
  if (curTag.type === 16 /* AttrTag */) {
3468
- path4 = `"${this.#getAttrTagName(curTag)}",${path4}`;
3483
+ path5 = `"${this.#getAttrTagName(curTag)}",${path5}`;
3469
3484
  } else if (!isControlFlowTag(curTag)) {
3470
3485
  break;
3471
3486
  }
3472
3487
  curTag = curTag.parent;
3473
3488
  }
3474
- return path4;
3489
+ return path5;
3475
3490
  }
3476
3491
  #getTagInputType(tag) {
3477
3492
  if (tag.type === 16 /* AttrTag */) {
@@ -3607,7 +3622,7 @@ function isValueAttribute(attr) {
3607
3622
  function resolveTagImport(from, def) {
3608
3623
  const filename = resolveTagFile(def);
3609
3624
  if (filename) {
3610
- return from ? (0, import_relative_import_path.relativeImportPath)(from, filename) : filename;
3625
+ return from ? (0, import_relative_import_path.relativeImportPath)(from, normalizePath(filename)) : filename;
3611
3626
  }
3612
3627
  }
3613
3628
  function resolveTagFile(def) {
@@ -3718,7 +3733,7 @@ function getExt(fileName) {
3718
3733
  }
3719
3734
 
3720
3735
  // src/processors/marko.ts
3721
- var import_path3 = __toESM(require("path"));
3736
+ var import_path4 = __toESM(require("path"));
3722
3737
 
3723
3738
  // src/util/project.ts
3724
3739
  var project_exports = {};
@@ -3735,7 +3750,7 @@ __export(project_exports, {
3735
3750
  });
3736
3751
  var import_strip_json_comments = require("@luxass/strip-json-comments");
3737
3752
  var import_module = require("module");
3738
- var import_path2 = __toESM(require("path"));
3753
+ var import_path3 = __toESM(require("path"));
3739
3754
  var defaultTypeLibs = {};
3740
3755
  var defaultMeta;
3741
3756
  var ignoreErrors = (_err) => {
@@ -3762,11 +3777,11 @@ function getTypeLibs(rootDir, ts, host) {
3762
3777
  const resolveTypeCompilerOptions = {
3763
3778
  moduleResolution: ts.ModuleResolutionKind.Bundler
3764
3779
  };
3765
- const markoRunGeneratedTypesFile = import_path2.default.join(
3780
+ const markoRunGeneratedTypesFile = import_path3.default.join(
3766
3781
  rootDir,
3767
3782
  ".marko-run/routes.d.ts"
3768
3783
  );
3769
- const resolveFromFile = import_path2.default.join(rootDir, "_.d.ts");
3784
+ const resolveFromFile = import_path3.default.join(rootDir, "_.d.ts");
3770
3785
  const internalTypesFile = defaultTypeLibs.internalTypesFile || ((_a = ts.resolveTypeReferenceDirective(
3771
3786
  "@marko/language-tools/marko.internal.d.ts",
3772
3787
  resolveFromFile,
@@ -3804,7 +3819,7 @@ function getTypeLibs(rootDir, ts, host) {
3804
3819
  }
3805
3820
  function getScriptLang(fileName, defaultScriptLang, ts, host) {
3806
3821
  if (fileName.endsWith(".d.marko")) return "ts" /* ts */;
3807
- const dir = import_path2.default.dirname(fileName);
3822
+ const dir = import_path3.default.dirname(fileName);
3808
3823
  const config = getConfig(dir);
3809
3824
  const cache = config.cache.get(getScriptLang);
3810
3825
  let scriptLang = cache == null ? void 0 : cache.get(dir);
@@ -3888,7 +3903,7 @@ function getMeta(dir) {
3888
3903
  function loadMeta(dir) {
3889
3904
  let cached = metaByDir.get(dir);
3890
3905
  if (!cached) {
3891
- const require2 = (0, import_module.createRequire)(import_path2.default.join(dir, "_.js"));
3906
+ const require2 = (0, import_module.createRequire)(import_path3.default.join(dir, "_.js"));
3892
3907
  const configPath = (() => {
3893
3908
  try {
3894
3909
  return require2.resolve("@marko/compiler/config");
@@ -3902,7 +3917,7 @@ function loadMeta(dir) {
3902
3917
  const translatorPath = require2.resolve(config.translator);
3903
3918
  cached = metaByTranslator.get(translatorPath);
3904
3919
  if (!cached) {
3905
- const compiler = require2(import_path2.default.dirname(configPath));
3920
+ const compiler = require2(import_path3.default.dirname(configPath));
3906
3921
  cached = {
3907
3922
  compiler,
3908
3923
  config: {
@@ -3963,13 +3978,13 @@ var marko_default = {
3963
3978
  extension: ".marko",
3964
3979
  create({ ts, host, configFile }) {
3965
3980
  const currentDirectory = host.getCurrentDirectory ? host.getCurrentDirectory() : ts.sys.getCurrentDirectory();
3966
- const defaultScriptLang = configFile && /tsconfig/g.test(configFile) ? "ts" /* ts */ : "js" /* js */;
3981
+ const defaultScriptLang = configFile && /tsconfig/.test(configFile) ? "ts" /* ts */ : "js" /* js */;
3967
3982
  const runtimeTypes = getTypeLibs(currentDirectory, ts, host);
3968
3983
  const rootNames = [
3969
3984
  runtimeTypes.internalTypesFile,
3970
3985
  runtimeTypes.markoTypesFile
3971
3986
  ];
3972
- const getJSFileIfTSExists = (source, importer) => host.fileExists(import_path3.default.join(importer, "..", `${source}.ts`)) && `${source}.js`;
3987
+ const getJSFileIfTSExists = (source, importer) => host.fileExists(import_path4.default.join(importer, "..", `${source}.ts`)) && `${source}.js`;
3973
3988
  const compileConfig = {
3974
3989
  output: "source",
3975
3990
  stripTypes: true,
@@ -4025,8 +4040,8 @@ var marko_default = {
4025
4040
  return getScriptLang(fileName, defaultScriptLang, ts, host) === "ts" /* ts */ ? ts.ScriptKind.TS : ts.ScriptKind.JS;
4026
4041
  },
4027
4042
  extract(fileName, code) {
4028
- const dir = import_path3.default.dirname(fileName);
4029
4043
  const parsed = parse(code, fileName);
4044
+ const dir = import_path4.default.dirname(parsed.filename);
4030
4045
  return extractScript({
4031
4046
  ts,
4032
4047
  parsed,
@@ -4043,7 +4058,7 @@ var marko_default = {
4043
4058
  },
4044
4059
  print({ extracted: { parsed } }) {
4045
4060
  const { code, map } = getCompiler(
4046
- import_path3.default.dirname(parsed.filename)
4061
+ import_path4.default.dirname(parsed.filename)
4047
4062
  ).compileSync(parsed.code, parsed.filename, compileConfig);
4048
4063
  return { code, map };
4049
4064
  },
@@ -4188,5 +4203,6 @@ function isDefinitionFile(fileName) {
4188
4203
  getPosition,
4189
4204
  isControlFlowTag,
4190
4205
  isDefinitionFile,
4206
+ normalizePath,
4191
4207
  parse
4192
4208
  });
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 path from "path";
1787
+ import path2 from "path";
1783
1788
  function getComponentFilename(from) {
1784
- const dir = path.dirname(from);
1785
- let nameNoExt = path.basename(from, ".marko");
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 path.join(dir, entry);
1801
+ return path2.join(dir, entry);
1797
1802
  }
1798
1803
  }
1799
1804
  }
@@ -3327,6 +3332,15 @@ ${isMutatedVar(tag.parent, valueLiteral) ? varLocal(`change__${valueLiteral}.`)
3327
3332
  })
3328
3333
  };
3329
3334
  }
3335
+ } else if (node.type === 24 /* Import */) {
3336
+ const imported = this.#ast.import(node);
3337
+ if (imported) {
3338
+ for (const specifier of imported.specifiers) {
3339
+ if (specifier.local.name === "Input") {
3340
+ return { typeParameters: void 0 };
3341
+ }
3342
+ }
3343
+ }
3330
3344
  }
3331
3345
  }
3332
3346
  }
@@ -3424,17 +3438,17 @@ ${isMutatedVar(tag.parent, valueLiteral) ? varLocal(`change__${valueLiteral}.`)
3424
3438
  return ((_a = this.#lookup.getTag(nameText)) == null ? void 0 : _a.targetProperty) || nameText.slice(nameText.lastIndexOf(":") + 1);
3425
3439
  }
3426
3440
  #getAttrTagPath(tag) {
3427
- let path4 = `"${this.#getAttrTagName(tag)}"`;
3441
+ let path5 = `"${this.#getAttrTagName(tag)}"`;
3428
3442
  let curTag = tag.parent;
3429
3443
  while (curTag) {
3430
3444
  if (curTag.type === 16 /* AttrTag */) {
3431
- path4 = `"${this.#getAttrTagName(curTag)}",${path4}`;
3445
+ path5 = `"${this.#getAttrTagName(curTag)}",${path5}`;
3432
3446
  } else if (!isControlFlowTag(curTag)) {
3433
3447
  break;
3434
3448
  }
3435
3449
  curTag = curTag.parent;
3436
3450
  }
3437
- return path4;
3451
+ return path5;
3438
3452
  }
3439
3453
  #getTagInputType(tag) {
3440
3454
  if (tag.type === 16 /* AttrTag */) {
@@ -3570,7 +3584,7 @@ function isValueAttribute(attr) {
3570
3584
  function resolveTagImport(from, def) {
3571
3585
  const filename = resolveTagFile(def);
3572
3586
  if (filename) {
3573
- return from ? relativeImportPath(from, filename) : filename;
3587
+ return from ? relativeImportPath(from, normalizePath(filename)) : filename;
3574
3588
  }
3575
3589
  }
3576
3590
  function resolveTagFile(def) {
@@ -3681,7 +3695,7 @@ function getExt(fileName) {
3681
3695
  }
3682
3696
 
3683
3697
  // src/processors/marko.ts
3684
- import path3 from "path";
3698
+ import path4 from "path";
3685
3699
 
3686
3700
  // src/util/project.ts
3687
3701
  var project_exports = {};
@@ -3698,7 +3712,7 @@ __export(project_exports, {
3698
3712
  });
3699
3713
  import { strip as stripJSONComments } from "@luxass/strip-json-comments";
3700
3714
  import { createRequire } from "module";
3701
- import path2 from "path";
3715
+ import path3 from "path";
3702
3716
  var defaultTypeLibs = {};
3703
3717
  var defaultMeta;
3704
3718
  var ignoreErrors = (_err) => {
@@ -3725,11 +3739,11 @@ function getTypeLibs(rootDir, ts, host) {
3725
3739
  const resolveTypeCompilerOptions = {
3726
3740
  moduleResolution: ts.ModuleResolutionKind.Bundler
3727
3741
  };
3728
- const markoRunGeneratedTypesFile = path2.join(
3742
+ const markoRunGeneratedTypesFile = path3.join(
3729
3743
  rootDir,
3730
3744
  ".marko-run/routes.d.ts"
3731
3745
  );
3732
- const resolveFromFile = path2.join(rootDir, "_.d.ts");
3746
+ const resolveFromFile = path3.join(rootDir, "_.d.ts");
3733
3747
  const internalTypesFile = defaultTypeLibs.internalTypesFile || ((_a = ts.resolveTypeReferenceDirective(
3734
3748
  "@marko/language-tools/marko.internal.d.ts",
3735
3749
  resolveFromFile,
@@ -3767,7 +3781,7 @@ function getTypeLibs(rootDir, ts, host) {
3767
3781
  }
3768
3782
  function getScriptLang(fileName, defaultScriptLang, ts, host) {
3769
3783
  if (fileName.endsWith(".d.marko")) return "ts" /* ts */;
3770
- const dir = path2.dirname(fileName);
3784
+ const dir = path3.dirname(fileName);
3771
3785
  const config = getConfig(dir);
3772
3786
  const cache = config.cache.get(getScriptLang);
3773
3787
  let scriptLang = cache == null ? void 0 : cache.get(dir);
@@ -3851,7 +3865,7 @@ function getMeta(dir) {
3851
3865
  function loadMeta(dir) {
3852
3866
  let cached = metaByDir.get(dir);
3853
3867
  if (!cached) {
3854
- const require2 = createRequire(path2.join(dir, "_.js"));
3868
+ const require2 = createRequire(path3.join(dir, "_.js"));
3855
3869
  const configPath = (() => {
3856
3870
  try {
3857
3871
  return require2.resolve("@marko/compiler/config");
@@ -3865,7 +3879,7 @@ function loadMeta(dir) {
3865
3879
  const translatorPath = require2.resolve(config.translator);
3866
3880
  cached = metaByTranslator.get(translatorPath);
3867
3881
  if (!cached) {
3868
- const compiler = require2(path2.dirname(configPath));
3882
+ const compiler = require2(path3.dirname(configPath));
3869
3883
  cached = {
3870
3884
  compiler,
3871
3885
  config: {
@@ -3926,13 +3940,13 @@ var marko_default = {
3926
3940
  extension: ".marko",
3927
3941
  create({ ts, host, configFile }) {
3928
3942
  const currentDirectory = host.getCurrentDirectory ? host.getCurrentDirectory() : ts.sys.getCurrentDirectory();
3929
- const defaultScriptLang = configFile && /tsconfig/g.test(configFile) ? "ts" /* ts */ : "js" /* js */;
3943
+ const defaultScriptLang = configFile && /tsconfig/.test(configFile) ? "ts" /* ts */ : "js" /* js */;
3930
3944
  const runtimeTypes = getTypeLibs(currentDirectory, ts, host);
3931
3945
  const rootNames = [
3932
3946
  runtimeTypes.internalTypesFile,
3933
3947
  runtimeTypes.markoTypesFile
3934
3948
  ];
3935
- const getJSFileIfTSExists = (source, importer) => host.fileExists(path3.join(importer, "..", `${source}.ts`)) && `${source}.js`;
3949
+ const getJSFileIfTSExists = (source, importer) => host.fileExists(path4.join(importer, "..", `${source}.ts`)) && `${source}.js`;
3936
3950
  const compileConfig = {
3937
3951
  output: "source",
3938
3952
  stripTypes: true,
@@ -3988,8 +4002,8 @@ var marko_default = {
3988
4002
  return getScriptLang(fileName, defaultScriptLang, ts, host) === "ts" /* ts */ ? ts.ScriptKind.TS : ts.ScriptKind.JS;
3989
4003
  },
3990
4004
  extract(fileName, code) {
3991
- const dir = path3.dirname(fileName);
3992
4005
  const parsed = parse(code, fileName);
4006
+ const dir = path4.dirname(parsed.filename);
3993
4007
  return extractScript({
3994
4008
  ts,
3995
4009
  parsed,
@@ -4006,7 +4020,7 @@ var marko_default = {
4006
4020
  },
4007
4021
  print({ extracted: { parsed } }) {
4008
4022
  const { code, map } = getCompiler(
4009
- path3.dirname(parsed.filename)
4023
+ path4.dirname(parsed.filename)
4010
4024
  ).compileSync(parsed.code, parsed.filename, compileConfig);
4011
4025
  return { code, map };
4012
4026
  },
@@ -4150,5 +4164,6 @@ export {
4150
4164
  getPosition,
4151
4165
  isControlFlowTag,
4152
4166
  isDefinitionFile,
4167
+ normalizePath,
4153
4168
  parse
4154
4169
  };
@@ -0,0 +1 @@
1
+ export declare const normalizePath: (filename: string) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marko/language-tools",
3
- "version": "2.5.59",
3
+ "version": "2.5.61",
4
4
  "description": "Marko Language Tools",
5
5
  "keywords": [
6
6
  "analysis",