@marko/language-tools 2.1.10 → 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
@@ -2551,9 +2551,7 @@ const attrTags = ${varShared(
2551
2551
  this.#extractor.write(SEP_COMMA_NEW_LINE);
2552
2552
  }
2553
2553
  if (tag.type === 16 /* AttrTag */) {
2554
- this.#extractor.write(
2555
- `[Symbol.iterator]: ${varShared("any")}${SEP_COMMA_NEW_LINE}`
2556
- );
2554
+ this.#extractor.write("[/*").copy(tag.name).write(`*/Symbol.iterator]: ${varShared("any")}${SEP_COMMA_NEW_LINE}`);
2557
2555
  }
2558
2556
  if (!hasInput) {
2559
2557
  this.#writeTagNameComment(tag);
@@ -3167,6 +3165,8 @@ function getExt(fileName) {
3167
3165
 
3168
3166
  // src/processors/marko.ts
3169
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)$/;
3170
3170
  var marko_default = {
3171
3171
  extension: ".marko",
3172
3172
  create({ ts, host, configFile }) {
@@ -3177,6 +3177,45 @@ var marko_default = {
3177
3177
  runtimeTypes.internalTypesFile,
3178
3178
  runtimeTypes.markoTypesFile
3179
3179
  ];
3180
+ const getJSFileIfTSExists = (source, importer) => host.fileExists(import_path3.default.join(importer, "..", `${source}.ts`)) && `${source}.js`;
3181
+ const compileConfig = {
3182
+ output: "source",
3183
+ stripTypes: true,
3184
+ sourceMaps: true,
3185
+ babelConfig: {
3186
+ babelrc: false,
3187
+ configFile: false,
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
+ ],
3210
+ caller: {
3211
+ name: "@marko/type-check",
3212
+ supportsStaticESM: true,
3213
+ supportsDynamicImport: true,
3214
+ supportsTopLevelAwait: true,
3215
+ supportsExportNamespaceFrom: true
3216
+ }
3217
+ }
3218
+ };
3180
3219
  if (runtimeTypes.markoRunTypesFile) {
3181
3220
  rootNames.push(runtimeTypes.markoRunTypesFile);
3182
3221
  }
@@ -3212,11 +3251,7 @@ var marko_default = {
3212
3251
  print({ extracted: { parsed } }) {
3213
3252
  const { code, map } = getCompiler(
3214
3253
  import_path3.default.dirname(parsed.filename)
3215
- ).compileSync(parsed.code, parsed.filename, {
3216
- output: "source",
3217
- stripTypes: true,
3218
- sourceMaps: true
3219
- });
3254
+ ).compileSync(parsed.code, parsed.filename, compileConfig);
3220
3255
  return { code, map };
3221
3256
  },
3222
3257
  printTypes({ printer, typeChecker, sourceFile, formatSettings }) {
@@ -3301,7 +3336,7 @@ var marko_default = {
3301
3336
  return ts.isTypeAliasDeclaration(statement) && statement.name.escapedText === "Input" && ts.isIndexedAccessTypeNode(statement.type) && ts.isTypeReferenceNode(statement.type.objectType) && ts.isIdentifier(statement.type.objectType.typeName) && statement.type.objectType.typeName.escapedText === "Component" && ts.isLiteralTypeNode(statement.type.indexType) && ts.isStringLiteral(statement.type.indexType.literal) && statement.type.indexType.literal.text === "input";
3302
3337
  }
3303
3338
  function isExportEmptyInputType(statement) {
3304
- return ts.isTypeAliasDeclaration(statement) && statement.name.escapedText === "Input" && ts.isTypeLiteralNode(statement.type) && !statement.typeParameters && statement.type.members.length === 0 || ts.isInterfaceDeclaration(statement) && statement.name.escapedText === "Input" && !statement.typeParameters && statement.members.length === 0;
3339
+ return ts.isTypeAliasDeclaration(statement) && statement.name.escapedText === "Input" && ts.isTypeLiteralNode(statement.type) && !statement.typeParameters && statement.type.members.length === 0 || ts.isInterfaceDeclaration(statement) && statement.name.escapedText === "Input" && !statement.heritageClauses && !statement.typeParameters && statement.members.length === 0;
3305
3340
  }
3306
3341
  function isExportComponentType(statement) {
3307
3342
  return ts.isExportDeclaration(statement) && statement.exportClause && ts.isNamedExports(statement.exportClause) && statement.exportClause.elements.length === 1 && statement.exportClause.elements[0].name.escapedText === "Component";
package/dist/index.mjs CHANGED
@@ -2519,9 +2519,7 @@ const attrTags = ${varShared(
2519
2519
  this.#extractor.write(SEP_COMMA_NEW_LINE);
2520
2520
  }
2521
2521
  if (tag.type === 16 /* AttrTag */) {
2522
- this.#extractor.write(
2523
- `[Symbol.iterator]: ${varShared("any")}${SEP_COMMA_NEW_LINE}`
2524
- );
2522
+ this.#extractor.write("[/*").copy(tag.name).write(`*/Symbol.iterator]: ${varShared("any")}${SEP_COMMA_NEW_LINE}`);
2525
2523
  }
2526
2524
  if (!hasInput) {
2527
2525
  this.#writeTagNameComment(tag);
@@ -3135,6 +3133,8 @@ function getExt(fileName) {
3135
3133
 
3136
3134
  // src/processors/marko.ts
3137
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)$/;
3138
3138
  var marko_default = {
3139
3139
  extension: ".marko",
3140
3140
  create({ ts, host, configFile }) {
@@ -3145,6 +3145,45 @@ var marko_default = {
3145
3145
  runtimeTypes.internalTypesFile,
3146
3146
  runtimeTypes.markoTypesFile
3147
3147
  ];
3148
+ const getJSFileIfTSExists = (source, importer) => host.fileExists(path3.join(importer, "..", `${source}.ts`)) && `${source}.js`;
3149
+ const compileConfig = {
3150
+ output: "source",
3151
+ stripTypes: true,
3152
+ sourceMaps: true,
3153
+ babelConfig: {
3154
+ babelrc: false,
3155
+ configFile: false,
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
+ ],
3178
+ caller: {
3179
+ name: "@marko/type-check",
3180
+ supportsStaticESM: true,
3181
+ supportsDynamicImport: true,
3182
+ supportsTopLevelAwait: true,
3183
+ supportsExportNamespaceFrom: true
3184
+ }
3185
+ }
3186
+ };
3148
3187
  if (runtimeTypes.markoRunTypesFile) {
3149
3188
  rootNames.push(runtimeTypes.markoRunTypesFile);
3150
3189
  }
@@ -3180,11 +3219,7 @@ var marko_default = {
3180
3219
  print({ extracted: { parsed } }) {
3181
3220
  const { code, map } = getCompiler(
3182
3221
  path3.dirname(parsed.filename)
3183
- ).compileSync(parsed.code, parsed.filename, {
3184
- output: "source",
3185
- stripTypes: true,
3186
- sourceMaps: true
3187
- });
3222
+ ).compileSync(parsed.code, parsed.filename, compileConfig);
3188
3223
  return { code, map };
3189
3224
  },
3190
3225
  printTypes({ printer, typeChecker, sourceFile, formatSettings }) {
@@ -3269,7 +3304,7 @@ var marko_default = {
3269
3304
  return ts.isTypeAliasDeclaration(statement) && statement.name.escapedText === "Input" && ts.isIndexedAccessTypeNode(statement.type) && ts.isTypeReferenceNode(statement.type.objectType) && ts.isIdentifier(statement.type.objectType.typeName) && statement.type.objectType.typeName.escapedText === "Component" && ts.isLiteralTypeNode(statement.type.indexType) && ts.isStringLiteral(statement.type.indexType.literal) && statement.type.indexType.literal.text === "input";
3270
3305
  }
3271
3306
  function isExportEmptyInputType(statement) {
3272
- return ts.isTypeAliasDeclaration(statement) && statement.name.escapedText === "Input" && ts.isTypeLiteralNode(statement.type) && !statement.typeParameters && statement.type.members.length === 0 || ts.isInterfaceDeclaration(statement) && statement.name.escapedText === "Input" && !statement.typeParameters && statement.members.length === 0;
3307
+ return ts.isTypeAliasDeclaration(statement) && statement.name.escapedText === "Input" && ts.isTypeLiteralNode(statement.type) && !statement.typeParameters && statement.type.members.length === 0 || ts.isInterfaceDeclaration(statement) && statement.name.escapedText === "Input" && !statement.heritageClauses && !statement.typeParameters && statement.members.length === 0;
3273
3308
  }
3274
3309
  function isExportComponentType(statement) {
3275
3310
  return ts.isExportDeclaration(statement) && statement.exportClause && ts.isNamedExports(statement.exportClause) && statement.exportClause.elements.length === 1 && statement.exportClause.elements[0].name.escapedText === "Component";
@@ -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.10",
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"