Skip to content

Commit 29e6c48

Browse files
committed
Make getPropFromRaw even safer
1 parent bdd47ef commit 29e6c48

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/compiler/commandLineParser.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import {
2929
emptyArray,
3030
endsWith,
3131
ensureTrailingDirectorySeparator,
32-
every,
3332
Expression,
3433
extend,
3534
Extension,
@@ -2974,7 +2973,7 @@ function parseJsonConfigFileContentWorker(
29742973
};
29752974

29762975
function getConfigFileSpecs(): ConfigFileSpecs {
2977-
const referencesOfRaw = getPropFromRaw("references", (element): element is ProjectReference => typeof element === "object", "object");
2976+
const referencesOfRaw = getPropFromRaw("references", (element): element is ProjectReference => !!element && typeof element === "object", "object");
29782977
const filesSpecs = toPropValue(getSpecsFromRaw("files"));
29792978
if (filesSpecs) {
29802979
const hasZeroOrNoReferences = referencesOfRaw === "no-prop" || isArray(referencesOfRaw) && referencesOfRaw.length === 0;
@@ -3049,7 +3048,7 @@ function parseJsonConfigFileContentWorker(
30493048

30503049
function getProjectReferences(basePath: string): readonly ProjectReference[] | undefined {
30513050
let projectReferences: ProjectReference[] | undefined;
3052-
const referencesOfRaw = getPropFromRaw("references", (element): element is ProjectReference => typeof element === "object", "object");
3051+
const referencesOfRaw = getPropFromRaw("references", (element): element is ProjectReference => !!element && typeof element === "object", "object");
30533052
if (isArray(referencesOfRaw)) {
30543053
for (const ref of referencesOfRaw) {
30553054
if (typeof ref.path !== "string") {
@@ -3079,9 +3078,10 @@ function parseJsonConfigFileContentWorker(
30793078

30803079
function getPropFromRaw<T>(prop: "files" | "include" | "exclude" | "references", validateElement: (value: unknown) => value is T, elementTypeName: string): PropOfRaw<T> {
30813080
if (hasProperty(raw, prop) && !isNullOrUndefined(raw[prop])) {
3082-
if (isArray(raw[prop])) {
3083-
const result = raw[prop] as T[];
3084-
if (!sourceFile && !every(result, validateElement)) {
3081+
const value = raw[prop];
3082+
if (isArray(value)) {
3083+
const result = filter(value, validateElement);
3084+
if (!sourceFile && result.length !== value.length) {
30853085
errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, prop, elementTypeName));
30863086
}
30873087
return result;

0 commit comments

Comments
 (0)