mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
Include *.json in the root files if they are specified as root (#34676)
Fixes #33827
This commit is contained in:
parent
a01c8ef764
commit
f12eee2e4b
@ -953,9 +953,7 @@ namespace ts {
|
||||
names.push(entry);
|
||||
}
|
||||
else {
|
||||
if (entry.scriptKind !== ScriptKind.JSON) {
|
||||
names.push(entry.hostFileName);
|
||||
}
|
||||
names.push(entry.hostFileName);
|
||||
}
|
||||
});
|
||||
return names;
|
||||
|
||||
@ -861,4 +861,76 @@ declare module '@custom/plugin' {
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("unittests:: tsserver:: Project Errors with resolveJsonModule", () => {
|
||||
function createSessionForTest({ include }: { include: readonly string[]; }) {
|
||||
const test: File = {
|
||||
path: `${projectRoot}/src/test.ts`,
|
||||
content: `import * as blabla from "./blabla.json";
|
||||
declare var console: any;
|
||||
console.log(blabla);`
|
||||
};
|
||||
const blabla: File = {
|
||||
path: `${projectRoot}/src/blabla.json`,
|
||||
content: "{}"
|
||||
};
|
||||
const tsconfig: File = {
|
||||
path: `${projectRoot}/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
compilerOptions: {
|
||||
resolveJsonModule: true,
|
||||
composite: true
|
||||
},
|
||||
include
|
||||
})
|
||||
};
|
||||
|
||||
const host = createServerHost([test, blabla, libFile, tsconfig]);
|
||||
const session = createSession(host, { canUseEvents: true });
|
||||
openFilesForSession([test], session);
|
||||
return { host, session, test, blabla, tsconfig };
|
||||
}
|
||||
|
||||
it("should not report incorrect error when json is root file found by tsconfig", () => {
|
||||
const { host, session, test } = createSessionForTest({
|
||||
include: ["./src/*.ts", "./src/*.json"]
|
||||
});
|
||||
verifyGetErrRequest({
|
||||
session,
|
||||
host,
|
||||
expected: [
|
||||
{
|
||||
file: test,
|
||||
syntax: [],
|
||||
semantic: [],
|
||||
suggestion: []
|
||||
}
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
it("should report error when json is not root file found by tsconfig", () => {
|
||||
const { host, session, test, blabla, tsconfig } = createSessionForTest({
|
||||
include: ["./src/*.ts"]
|
||||
});
|
||||
const span = protocolTextSpanFromSubstring(test.content, `"./blabla.json"`);
|
||||
verifyGetErrRequest({
|
||||
session,
|
||||
host,
|
||||
expected: [{
|
||||
file: test,
|
||||
syntax: [],
|
||||
semantic: [
|
||||
createDiagnostic(
|
||||
span.start,
|
||||
span.end,
|
||||
Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern,
|
||||
[blabla.path, tsconfig.path]
|
||||
)
|
||||
],
|
||||
suggestion: []
|
||||
}]
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user