Skip to content

Output Config Option Values in Canonical Case #58735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
310 changes: 155 additions & 155 deletions src/compiler/commandLineParser.ts

Large diffs are not rendered by default.

129 changes: 125 additions & 4 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1778,16 +1778,16 @@ export function createSet<TElement, THash = number>(getHashCode: (element: TElem
get size() {
return size;
},
forEach(action: (value: TElement, key: TElement, set: Set<TElement>) => void): void {
forEach(callback: (value: TElement, key: TElement, set: Set<TElement>) => void): void {
for (const elements of arrayFrom(multiMap.values())) {
if (isArray(elements)) {
for (const element of elements) {
action(element, element, set);
callback(element, element, set);
}
}
else {
const element = elements;
action(element, element, set);
callback(element, element, set);
}
}
},
Expand All @@ -1811,6 +1811,118 @@ export function createSet<TElement, THash = number>(getHashCode: (element: TElem
return set;
}

/**
* Creates a Map with custom equality and hash code functionality. This is useful when you
* want to use something looser than object identity - e.g. "has the same span".
*
* If `equals(a, b)`, it must be the case that `getHashCode(a) === getHashCode(b)`.
* The converse is not required.
*
* @internal
*/
export function createMap<TKey, TValue, THash = number>(getHashCode: (key: TKey) => THash, equals: EqualityComparer<TKey>): Map<TKey, TValue> {
const multiMap = new Map<THash, Map<TKey, TValue>>();
let size = 0;

function* entriesIterator(): IterableIterator<[TKey, TValue]> {
for (const candidates of multiMap.values()) {
yield* candidates;
}
}

const map: Map<TKey, TValue> = {
has(key: TKey): boolean {
const hash = getHashCode(key);
if (!multiMap.has(hash)) return false;
const candidates = multiMap.get(hash)!;
for (const candidateKey of candidates.keys()) {
if (equals(candidateKey, key)) {
return true;
}
}
return false;
},
get(key: TKey): TValue | undefined {
const hash = getHashCode(key);
if (!multiMap.has(hash)) return undefined;
const candidates = multiMap.get(hash)!;
for (const [candidateKey, candidateValue] of candidates) {
if (equals(candidateKey, key)) {
return candidateValue;
}
}
},
set(key: TKey, value: TValue): Map<TKey, TValue> {
const hash = getHashCode(key);
if (multiMap.has(hash)) {
const candidates = multiMap.get(hash)!;
for (const candidateKey of candidates.keys()) {
if (equals(candidateKey, key)) {
candidates.delete(candidateKey);
candidates.set(key, value);
return this;
}
}
candidates.set(key, value);
}
else {
multiMap.set(hash, new Map([[key, value]]));
}
size++;
return this;
},
delete(key: TKey): boolean {
const hash = getHashCode(key);
if (!multiMap.has(hash)) return false;
const candidates = multiMap.get(hash)!;
for (const candidateKey of candidates.keys()) {
if (equals(candidateKey, key)) {
candidates.delete(candidateKey);
size--;
return true;
}
}
return false;
},
clear(): void {
multiMap.clear();
size = 0;
},
get size() {
return size;
},
forEach(callback: (value: TValue, key: TKey, map: Map<TKey, TValue>) => void): void {
for (const candidates of multiMap.values()) {
candidates.forEach(callback);
}
},
*keys(): IterableIterator<TKey> {
for (const candidates of multiMap.values()) {
yield* candidates.keys();
}
},
*values(): IterableIterator<TValue> {
for (const candidates of multiMap.values()) {
yield* candidates.values();
}
},
entries: entriesIterator,
[Symbol.iterator]: entriesIterator,
[Symbol.toStringTag]: multiMap[Symbol.toStringTag],
};

return map;
}

/** @internal */
export function entriesToCaseInsensitiveMap<TKey extends string, TValue>(entries: Iterable<[TKey, TValue]>): Map<TKey, TValue> {
const map = createMap<TKey, TValue, string>(toUpperCase, equateStringsCaseInsensitive);
for (const [key, value] of entries) {
map.set(key, value);
}
return map;
}

/**
* Tests whether a value is an array.
*
Expand Down Expand Up @@ -1899,14 +2011,23 @@ export function identity<T>(x: T) {
}

/**
* Returns lower case string
* Returns a lower case string
*
* @internal
*/
export function toLowerCase(x: string) {
return x.toLowerCase();
}

/**
* Returns an upper case string
*
* @internal
*/
export function toUpperCase(x: string) {
return x.toUpperCase();
}

// We convert the file names to lower case as key for file name on case insensitive file system
// While doing so we need to handle special characters (eg \u0130) to ensure that we dont convert
// it to lower case, fileName with its lowercase form can exist along side it.
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ import {
getLinesBetweenPositions,
getLineStarts,
getModeForUsageLocation,
getNameOfCompilerOptionValue,
getNameOfDeclaration,
getNodeChildren,
getNormalizedAbsolutePath,
Expand Down Expand Up @@ -9114,7 +9115,7 @@ export function getStrictOptionValue(compilerOptions: CompilerOptions, flag: Str

/** @internal */
export function getNameOfScriptTarget(scriptTarget: ScriptTarget): string | undefined {
return forEachEntry(targetOptionDeclaration.type, (value, key) => value === scriptTarget ? key : undefined);
return getNameOfCompilerOptionValue(scriptTarget, targetOptionDeclaration.type);
}

/** @internal */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ Projects::
.
Errors::
error TS5080: Watch option 'fallbackPolling' requires a value of type string.
error TS6046: Argument for '--fallbackPolling' option must be: 'fixedinterval', 'priorityinterval', 'dynamicpriority', 'fixedchunksize'.
error TS6046: Argument for '--fallbackPolling' option must be: 'fixedInterval', 'priorityInterval', 'dynamicPriority', 'fixedChunkSize'.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ FileNames::
0.ts
Errors::
error TS6044: Compiler option 'module' expects an argument.
error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2020', 'es2022', 'esnext', 'node16', 'nodenext', 'preserve'.
error TS6046: Argument for '--module' option must be: 'None', 'CommonJS', 'AMD', 'System', 'UMD', 'ES2015', 'ES6', 'ES2020', 'ES2022', 'ESNext', 'Node16', 'NodeNext', 'Preserve'.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ FileNames::
0.ts
Errors::
error TS6044: Compiler option 'moduleResolution' expects an argument.
error TS6046: Argument for '--moduleResolution' option must be: 'node10', 'classic', 'node16', 'nodenext', 'bundler'.
error TS6046: Argument for '--moduleResolution' option must be: 'Node10', 'Classic', 'Node16', 'NodeNext', 'Bundler'.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ FileNames::
0.ts
Errors::
error TS6044: Compiler option 'target' expects an argument.
error TS6046: Argument for '--target' option must be: 'es5', 'es6', 'es2015', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'es2021', 'es2022', 'es2023', 'esnext'.
error TS6046: Argument for '--target' option must be: 'ES5', 'ES2015', 'ES6', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', 'ES2022', 'ES2023', 'ESNext'.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ FileNames::
0.ts
Errors::
error TS5080: Watch option 'fallbackPolling' requires a value of type string.
error TS6046: Argument for '--fallbackPolling' option must be: 'fixedinterval', 'priorityinterval', 'dynamicpriority', 'fixedchunksize'.
error TS6046: Argument for '--fallbackPolling' option must be: 'fixedInterval', 'priorityInterval', 'dynamicPriority', 'fixedChunkSize'.
Loading