@marko/language-tools 2.1.11 → 2.2.0

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.js CHANGED
@@ -3165,6 +3165,8 @@ function getExt(fileName) {
3165
3165
 
3166
3166
  // src/processors/marko.ts
3167
3167
  var import_path3 = __toESM(require("path"));
3168
+ var isRemapExtensionReg = /\.ts$/;
3169
+ var skipRemapExtensionsReg = /\.(?:[cm]?jsx?|json|marko|css|less|sass|scss|styl|stylus|pcss|postcss|sss|a?png|jpe?g|jfif|pipeg|pjp|gif|svg|ico|web[pm]|avif|mp4|ogg|mp3|wav|flac|aac|opus|woff2?|eot|[ot]tf|webmanifest|pdf|txt)$/;
3168
3170
  var marko_default = {
3169
3171
  extension: ".marko",
3170
3172
  create({ ts, host, configFile }) {
@@ -3175,6 +3177,7 @@ var marko_default = {
3175
3177
  runtimeTypes.internalTypesFile,
3176
3178
  runtimeTypes.markoTypesFile
3177
3179
  ];
3180
+ const getJSFileIfTSExists = (source, importer) => host.fileExists(import_path3.default.join(importer, "..", `${source}.ts`)) && `${source}.js`;
3178
3181
  const compileConfig = {
3179
3182
  output: "source",
3180
3183
  stripTypes: true,
@@ -3183,6 +3186,27 @@ var marko_default = {
3183
3186
  babelrc: false,
3184
3187
  configFile: false,
3185
3188
  browserslistConfigFile: false,
3189
+ plugins: [
3190
+ {
3191
+ visitor: {
3192
+ // Find all relative imports in Marko template
3193
+ // if they would map to a `.ts` file, then we convert it to a `.js` file for the output.
3194
+ "ImportDeclaration|ExportNamedDeclaration"(decl) {
3195
+ var _a;
3196
+ const { node } = decl;
3197
+ const value = (_a = node.source) == null ? void 0 : _a.value;
3198
+ const importKind = "importKind" in node ? node.importKind : void 0;
3199
+ if ((value == null ? void 0 : value[0]) === "." && (!importKind || importKind === "value") && !skipRemapExtensionsReg.test(value)) {
3200
+ const filename = decl.hub.file.opts.filename;
3201
+ const remap = isRemapExtensionReg.test(value) ? `${value.slice(0, -2)}js` : getJSFileIfTSExists(value, filename) || getJSFileIfTSExists(`${value}/index`, filename);
3202
+ if (remap) {
3203
+ node.source.value = remap;
3204
+ }
3205
+ }
3206
+ }
3207
+ }
3208
+ }
3209
+ ],
3186
3210
  caller: {
3187
3211
  name: "@marko/type-check",
3188
3212
  supportsStaticESM: true,
package/dist/index.mjs CHANGED
@@ -3133,6 +3133,8 @@ function getExt(fileName) {
3133
3133
 
3134
3134
  // src/processors/marko.ts
3135
3135
  import path3 from "path";
3136
+ var isRemapExtensionReg = /\.ts$/;
3137
+ var skipRemapExtensionsReg = /\.(?:[cm]?jsx?|json|marko|css|less|sass|scss|styl|stylus|pcss|postcss|sss|a?png|jpe?g|jfif|pipeg|pjp|gif|svg|ico|web[pm]|avif|mp4|ogg|mp3|wav|flac|aac|opus|woff2?|eot|[ot]tf|webmanifest|pdf|txt)$/;
3136
3138
  var marko_default = {
3137
3139
  extension: ".marko",
3138
3140
  create({ ts, host, configFile }) {
@@ -3143,6 +3145,7 @@ var marko_default = {
3143
3145
  runtimeTypes.internalTypesFile,
3144
3146
  runtimeTypes.markoTypesFile
3145
3147
  ];
3148
+ const getJSFileIfTSExists = (source, importer) => host.fileExists(path3.join(importer, "..", `${source}.ts`)) && `${source}.js`;
3146
3149
  const compileConfig = {
3147
3150
  output: "source",
3148
3151
  stripTypes: true,
@@ -3151,6 +3154,27 @@ var marko_default = {
3151
3154
  babelrc: false,
3152
3155
  configFile: false,
3153
3156
  browserslistConfigFile: false,
3157
+ plugins: [
3158
+ {
3159
+ visitor: {
3160
+ // Find all relative imports in Marko template
3161
+ // if they would map to a `.ts` file, then we convert it to a `.js` file for the output.
3162
+ "ImportDeclaration|ExportNamedDeclaration"(decl) {
3163
+ var _a;
3164
+ const { node } = decl;
3165
+ const value = (_a = node.source) == null ? void 0 : _a.value;
3166
+ const importKind = "importKind" in node ? node.importKind : void 0;
3167
+ if ((value == null ? void 0 : value[0]) === "." && (!importKind || importKind === "value") && !skipRemapExtensionsReg.test(value)) {
3168
+ const filename = decl.hub.file.opts.filename;
3169
+ const remap = isRemapExtensionReg.test(value) ? `${value.slice(0, -2)}js` : getJSFileIfTSExists(value, filename) || getJSFileIfTSExists(`${value}/index`, filename);
3170
+ if (remap) {
3171
+ node.source.value = remap;
3172
+ }
3173
+ }
3174
+ }
3175
+ }
3176
+ }
3177
+ ],
3154
3178
  caller: {
3155
3179
  name: "@marko/type-check",
3156
3180
  supportsStaticESM: true,
@@ -32,5 +32,5 @@ export interface PrintContext {
32
32
  formatSettings: Required<ts.FormatCodeSettings>;
33
33
  }
34
34
  export declare const extensions: `.${string}`[];
35
- export declare function create(options: Parameters<ProcessorConfig["create"]>[0]): Record<`.${string}`, Processor>;
35
+ export declare function create(options: CreateProcessorOptions): Record<`.${string}`, Processor>;
36
36
  export declare function has(fileName: string): boolean;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@marko/language-tools",
3
3
  "description": "Marko Language Tools",
4
- "version": "2.1.11",
4
+ "version": "2.2.0",
5
5
  "bugs": "https://github.com/marko-js/language-server/issues/new?template=Bug_report.md",
6
6
  "peerDependencies": {
7
7
  "@marko/compiler": "^5.28.4"