Fix dts file detection (#20018)
This commit is contained in:
1 parent
b69ba60e5a
commit
60600efbb6
13 files changed
+108
-41
No files matched your search
@@ -4,6 +4,7 @@ import createError from "../../common/parser-create-error.js";
|
||||
import { tryCombinationsSync } from "../../utilities/try-combinations.js";
|
||||
import postprocess from "./postprocess/index.js";
|
||||
import createParser from "./utilities/create-parser.js";
|
||||
import { isDtsFile } from "./utilities/is-dts-file.js";
|
||||
import jsxRegexp from "./utilities/jsx-regexp.evaluate.js";
|
||||
import { shouldEnableJsx } from "./utilities/jsx-support.js";
|
||||
import {
|
||||
@@ -103,10 +104,7 @@ function parseJs(text, options) {
|
||||
function getLanguageCombinations(text, options) {
|
||||
const filepath = options?.filepath;
|
||||
|
||||
if (
|
||||
typeof filepath === "string" &&
|
||||
filepath.toLowerCase().endsWith(".d.ts")
|
||||
) {
|
||||
if (isDtsFile(filepath)) {
|
||||
return ["dts"];
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
function isDtsFile(filepath) {
|
||||
return typeof filepath === "string" && /\.d\.(?:ts|mts|cts)$/i.test(filepath);
|
||||
}
|
||||
|
||||
export { isDtsFile };
|
||||
@@ -13,8 +13,6 @@ export function getSourceType(filepath) {
|
||||
return;
|
||||
}
|
||||
|
||||
filepath = filepath.toLowerCase();
|
||||
|
||||
if (/\.(?:mjs|mts)$/i.test(filepath)) {
|
||||
return SOURCE_TYPE_MODULE;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import createError from "../../common/parser-create-error.js";
|
||||
import { tryCombinationsSync } from "../../utilities/try-combinations.js";
|
||||
import postprocess from "./postprocess/index.js";
|
||||
import createParser from "./utilities/create-parser.js";
|
||||
import { isDtsFile } from "./utilities/is-dts-file.js";
|
||||
import jsxRegexp from "./utilities/jsx-regexp.evaluate.js";
|
||||
import { shouldEnableJsx } from "./utilities/jsx-support.js";
|
||||
import {
|
||||
@@ -87,10 +88,7 @@ function parseJs(text, options) {
|
||||
function getLanguageCombinations(text, options) {
|
||||
const filepath = options?.filepath;
|
||||
|
||||
if (
|
||||
typeof filepath === "string" &&
|
||||
filepath.toLowerCase().endsWith(".d.ts")
|
||||
) {
|
||||
if (isDtsFile(filepath)) {
|
||||
return ["dts"];
|
||||
}
|
||||
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
|
||||
|
||||
exports[`const-without-initializer.d.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80 (default) |
|
||||
=====================================input======================================
|
||||
export const version: string;
|
||||
|
||||
=====================================output=====================================
|
||||
export const version: string;
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`const-without-initializer-in-namespace.d.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80 (default) |
|
||||
=====================================input======================================
|
||||
export namespace builders {
|
||||
const breakParent: string;
|
||||
}
|
||||
|
||||
=====================================output=====================================
|
||||
export namespace builders {
|
||||
const breakParent: string;
|
||||
}
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
@@ -0,0 +1,91 @@
|
||||
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
|
||||
|
||||
exports[`const-without-initializer.d.cts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80 (default) |
|
||||
=====================================input======================================
|
||||
const version: string;
|
||||
|
||||
=====================================output=====================================
|
||||
const version: string;
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`const-without-initializer.d.mts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80 (default) |
|
||||
=====================================input======================================
|
||||
export const version: string;
|
||||
|
||||
=====================================output=====================================
|
||||
export const version: string;
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`const-without-initializer.d.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80 (default) |
|
||||
=====================================input======================================
|
||||
export const version: string;
|
||||
|
||||
=====================================output=====================================
|
||||
export const version: string;
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`const-without-initializer-in-namespace.d.cts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80 (default) |
|
||||
=====================================input======================================
|
||||
namespace builders {
|
||||
const breakParent: string;
|
||||
}
|
||||
|
||||
=====================================output=====================================
|
||||
namespace builders {
|
||||
const breakParent: string;
|
||||
}
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`const-without-initializer-in-namespace.d.mts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80 (default) |
|
||||
=====================================input======================================
|
||||
export namespace builders {
|
||||
const breakParent: string;
|
||||
}
|
||||
|
||||
=====================================output=====================================
|
||||
export namespace builders {
|
||||
const breakParent: string;
|
||||
}
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`const-without-initializer-in-namespace.d.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80 (default) |
|
||||
=====================================input======================================
|
||||
export namespace builders {
|
||||
const breakParent: string;
|
||||
}
|
||||
|
||||
=====================================output=====================================
|
||||
export namespace builders {
|
||||
const breakParent: string;
|
||||
}
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace builders {
|
||||
const breakParent: string;
|
||||
}
|
||||
File renamed without changes.
@@ -0,0 +1,3 @@
|
||||
export namespace builders {
|
||||
const breakParent: string;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
const version: string;
|
||||
File renamed without changes.
@@ -0,0 +1 @@
|
||||
export const version: string;
|
||||
File renamed without changes.
Reference in new issue
Block a user