Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a32bc98

Browse filesBrowse files
author
Arthur Ozga
committed
respond to comments
1 parent 0588f8b commit a32bc98
Copy full SHA for a32bc98

7 files changed

+101-89Lines changed: 101 additions & 89 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/compiler/checker.ts‎

Copy file name to clipboardExpand all lines: src/compiler/checker.ts
+32-33Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,35 +2278,10 @@ namespace ts {
22782278
return result;
22792279
}
22802280

2281-
function typeFormatFlagsToNodeBuilderFlags(flags: TypeFormatFlags): NodeBuilderFlags {
2282-
let result = NodeBuilderFlags.None;
2283-
if (flags === TypeFormatFlags.None) {
2284-
return result;
2285-
}
2286-
if (flags & TypeFormatFlags.NoTruncation) {
2287-
result |= NodeBuilderFlags.NoTruncation;
2288-
}
2289-
if (flags & TypeFormatFlags.UseFullyQualifiedType) {
2290-
result |= NodeBuilderFlags.UseFullyQualifiedType;
2291-
}
2292-
if (flags & TypeFormatFlags.SuppressAnyReturnType) {
2293-
result |= NodeBuilderFlags.SuppressAnyReturnType;
2294-
}
2295-
if (flags & TypeFormatFlags.WriteArrayAsGenericType) {
2296-
result |= NodeBuilderFlags.WriteArrayAsGenericType;
2297-
}
2298-
if (flags & TypeFormatFlags.WriteTypeArgumentsOfSignature) {
2299-
result |= NodeBuilderFlags.WriteTypeArgumentsOfSignature;
2300-
}
2301-
2302-
return result;
2303-
}
2304-
23052281
function typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string {
2306-
const typeNode = nodeBuilder.typeToTypeNode(type, enclosingDeclaration, typeFormatFlagsToNodeBuilderFlags(flags) | NodeBuilderFlags.ignoreErrors);
2282+
const typeNode = nodeBuilder.typeToTypeNode(type, enclosingDeclaration, toNodeBuilderFlags(flags) | NodeBuilderFlags.ignoreErrors);
23072283
Debug.assert(typeNode !== undefined, "should always get typenode?");
2308-
const newLine = NewLineKind.None;
2309-
const options = { newLine, removeComments: true };
2284+
const options = { removeComments: true };
23102285
const writer = createTextWriter("");
23112286
const printer = createPrinter(options, writer);
23122287
const sourceFile = enclosingDeclaration && getSourceFileOfNode(enclosingDeclaration);
@@ -2318,6 +2293,30 @@ namespace ts {
23182293
return result.substr(0, maxLength - "...".length) + "...";
23192294
}
23202295
return result;
2296+
2297+
function toNodeBuilderFlags(flags?: TypeFormatFlags): NodeBuilderFlags {
2298+
let result = NodeBuilderFlags.None;
2299+
if (!flags) {
2300+
return result;
2301+
}
2302+
if (flags & TypeFormatFlags.NoTruncation) {
2303+
result |= NodeBuilderFlags.NoTruncation;
2304+
}
2305+
if (flags & TypeFormatFlags.UseFullyQualifiedType) {
2306+
result |= NodeBuilderFlags.UseFullyQualifiedType;
2307+
}
2308+
if (flags & TypeFormatFlags.SuppressAnyReturnType) {
2309+
result |= NodeBuilderFlags.SuppressAnyReturnType;
2310+
}
2311+
if (flags & TypeFormatFlags.WriteArrayAsGenericType) {
2312+
result |= NodeBuilderFlags.WriteArrayAsGenericType;
2313+
}
2314+
if (flags & TypeFormatFlags.WriteTypeArgumentsOfSignature) {
2315+
result |= NodeBuilderFlags.WriteTypeArgumentsOfSignature;
2316+
}
2317+
2318+
return result;
2319+
}
23212320
}
23222321

23232322
function createNodeBuilder() {
@@ -2423,7 +2422,7 @@ namespace ts {
24232422
}
24242423
if (type.flags & TypeFlags.TypeParameter && (type as TypeParameter).isThisType) {
24252424
if (context.flags & NodeBuilderFlags.inObjectTypeLiteral) {
2426-
if (!context.encounteredError && !(context.flags & NodeBuilderFlags.allowThisInObjectLiteral)) {
2425+
if (!context.encounteredError && !(context.flags & NodeBuilderFlags.AllowThisInObjectLiteral)) {
24272426
context.encounteredError = true;
24282427
}
24292428
}
@@ -2455,7 +2454,7 @@ namespace ts {
24552454
return inElementType ? createParenthesizedType(unionOrIntersectionTypeNode) : unionOrIntersectionTypeNode;
24562455
}
24572456
else {
2458-
if (!context.encounteredError && !(context.flags & NodeBuilderFlags.allowEmptyUnionOrIntersection)) {
2457+
if (!context.encounteredError && !(context.flags & NodeBuilderFlags.AllowEmptyUnionOrIntersection)) {
24592458
context.encounteredError = true;
24602459
}
24612460
return undefined;
@@ -2629,7 +2628,7 @@ namespace ts {
26292628
return createTupleTypeNode(tupleConstituentNodes);
26302629
}
26312630
}
2632-
if (!context.encounteredError && !(context.flags & NodeBuilderFlags.allowEmptyTuple)) {
2631+
if (!context.encounteredError && !(context.flags & NodeBuilderFlags.AllowEmptyTuple)) {
26332632
context.encounteredError = true;
26342633
}
26352634
return undefined;
@@ -2901,7 +2900,7 @@ namespace ts {
29012900

29022901
if (expectsIdentifier && chain.length !== 1
29032902
&& !context.encounteredError
2904-
&& !(context.flags & NodeBuilderFlags.allowQualifedNameInPlaceOfIdentifier)) {
2903+
&& !(context.flags & NodeBuilderFlags.AllowQualifedNameInPlaceOfIdentifier)) {
29052904
context.encounteredError = true;
29062905
}
29072906
return createEntityNameFromSymbolChain(chain, chain.length - 1);
@@ -2923,7 +2922,7 @@ namespace ts {
29232922
}
29242923
}
29252924
if (typeParameters && typeParameters.length > 0) {
2926-
if (!context.encounteredError && !(context.flags & NodeBuilderFlags.allowTypeParameterInQualifiedName)) {
2925+
if (!context.encounteredError && !(context.flags & NodeBuilderFlags.AllowTypeParameterInQualifiedName)) {
29272926
context.encounteredError = true;
29282927
}
29292928
typeParameterNodes = toTypeArgumentNodes(typeParameters, context);
@@ -2981,7 +2980,7 @@ namespace ts {
29812980
if (declaration.parent && declaration.parent.kind === SyntaxKind.VariableDeclaration) {
29822981
return declarationNameToString((<VariableDeclaration>declaration.parent).name);
29832982
}
2984-
if (!context.encounteredError && !(context.flags & NodeBuilderFlags.allowAnonymousIdentifier)) {
2983+
if (!context.encounteredError && !(context.flags & NodeBuilderFlags.AllowAnonymousIdentifier)) {
29852984
context.encounteredError = true;
29862985
}
29872986
switch (declaration.kind) {
Collapse file

‎src/compiler/emitter.ts‎

Copy file name to clipboardExpand all lines: src/compiler/emitter.ts
+11-10Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,7 @@ namespace ts {
234234
writeBundle
235235
};
236236

237-
/**
238-
* If `sourceFile` is `undefined`, `node` must be a synthesized `TypeNode`.
239-
*/
240-
function printNode(hint: EmitHint, node: TypeNode, sourceFile: undefined): string;
241-
function printNode(hint: EmitHint, node: Node, sourceFile: SourceFile): string;
242-
function printNode(hint: EmitHint, node: Node, sourceFile: SourceFile | undefined): string {
237+
function printNode(hint: EmitHint, node: Node, sourceFile: SourceFile): string {
243238
switch (hint) {
244239
case EmitHint.SourceFile:
245240
Debug.assert(isSourceFile(node), "Expected a SourceFile node.");
@@ -269,6 +264,11 @@ namespace ts {
269264
return endPrint();
270265
}
271266

267+
/**
268+
* If `sourceFile` is `undefined`, `node` must be a synthesized `TypeNode`.
269+
*/
270+
function writeNode(hint: EmitHint, node: TypeNode, sourceFile: undefined, output: EmitTextWriter): void;
271+
function writeNode(hint: EmitHint, node: Node, sourceFile: SourceFile, output: EmitTextWriter): void;
272272
function writeNode(hint: EmitHint, node: Node, sourceFile: SourceFile | undefined, output: EmitTextWriter) {
273273
const previousWriter = writer;
274274
setWriter(output);
@@ -961,6 +961,7 @@ namespace ts {
961961

962962
function emitTypeLiteral(node: TypeLiteralNode) {
963963
write("{");
964+
// TODO: fix added indentation so we can remove this check.
964965
if (node.members.length > 0) {
965966
emitList(node, node.members, getEmitFlags(node) & EmitFlags.SingleLine ? ListFormat.SingleLineTypeLiteralMembers : ListFormat.MultiLineTypeLiteralMembers);
966967
}
@@ -2525,7 +2526,7 @@ namespace ts {
25252526

25262527
const firstChild = children[0];
25272528
if (firstChild === undefined) {
2528-
return !(rangeIsOnSingleLine(parentNode, currentSourceFile));
2529+
return !rangeIsOnSingleLine(parentNode, currentSourceFile);
25292530
}
25302531
else if (positionIsSynthesized(parentNode.pos) || nodeIsSynthesized(firstChild)) {
25312532
return synthesizedNodeStartsOnNewLine(firstChild, format);
@@ -2551,7 +2552,7 @@ namespace ts {
25512552
return synthesizedNodeStartsOnNewLine(previousNode, format) || synthesizedNodeStartsOnNewLine(nextNode, format);
25522553
}
25532554
else {
2554-
return !(rangeEndIsOnSameLineAsRangeStart(previousNode, nextNode, currentSourceFile));
2555+
return !rangeEndIsOnSameLineAsRangeStart(previousNode, nextNode, currentSourceFile);
25552556
}
25562557
}
25572558
else {
@@ -2570,13 +2571,13 @@ namespace ts {
25702571

25712572
const lastChild = lastOrUndefined(children);
25722573
if (lastChild === undefined) {
2573-
return !(rangeIsOnSingleLine(parentNode, currentSourceFile));
2574+
return !rangeIsOnSingleLine(parentNode, currentSourceFile);
25742575
}
25752576
else if (positionIsSynthesized(parentNode.pos) || nodeIsSynthesized(lastChild)) {
25762577
return synthesizedNodeStartsOnNewLine(lastChild, format);
25772578
}
25782579
else {
2579-
return !(rangeEndPositionsAreOnSameLine(parentNode, lastChild, currentSourceFile));
2580+
return !rangeEndPositionsAreOnSameLine(parentNode, lastChild, currentSourceFile);
25802581
}
25812582
}
25822583
else {
Collapse file

‎src/compiler/factory.ts‎

Copy file name to clipboardExpand all lines: src/compiler/factory.ts
+32-28Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,6 @@
22
/// <reference path="utilities.ts"/>
33

44
namespace ts {
5-
export const nullTransformationContext: TransformationContext = {
6-
enableEmitNotification: noop,
7-
enableSubstitution: noop,
8-
endLexicalEnvironment: () => undefined,
9-
getCompilerOptions: notImplemented,
10-
getEmitHost: notImplemented,
11-
getEmitResolver: notImplemented,
12-
hoistFunctionDeclaration: noop,
13-
hoistVariableDeclaration: noop,
14-
isEmitNotificationEnabled: notImplemented,
15-
isSubstitutionEnabled: notImplemented,
16-
onEmitNode: noop,
17-
onSubstituteNode: notImplemented,
18-
readEmitHelpers: notImplemented,
19-
requestEmitHelper: noop,
20-
resumeLexicalEnvironment: noop,
21-
startLexicalEnvironment: noop,
22-
suspendLexicalEnvironment: noop
23-
};
24-
255
function createSynthesizedNode(kind: SyntaxKind): Node {
266
const node = createNode(kind, -1, -1);
277
node.flags |= NodeFlags.Synthesized;
@@ -127,13 +107,18 @@ namespace ts {
127107

128108
// Identifiers
129109

110+
export function createIdentifier(text: string): Identifier;
111+
/* @internal */
112+
export function createIdentifier(text: string, typeArguments: TypeNode[]): Identifier;
130113
export function createIdentifier(text: string, typeArguments?: TypeNode[]): Identifier {
131114
const node = <Identifier>createSynthesizedNode(SyntaxKind.Identifier);
132115
node.text = escapeIdentifier(text);
133116
node.originalKeywordKind = text ? stringToToken(text) : SyntaxKind.Unknown;
134117
node.autoGenerateKind = GeneratedIdentifierKind.None;
135118
node.autoGenerateId = 0;
136-
node.typeArguments = asNodeArray(typeArguments);
119+
if (typeArguments) {
120+
node.typeArguments = createNodeArray(typeArguments);
121+
}
137122
return node;
138123
}
139124

@@ -299,13 +284,13 @@ namespace ts {
299284
// Type Elements
300285

301286
export function createPropertySignature(modifiers: Modifier[] | undefined, name: PropertyName | string, questionToken: QuestionToken | undefined, type: TypeNode | undefined, initializer: Expression | undefined): PropertySignature {
302-
const propertySignature = createSynthesizedNode(SyntaxKind.PropertySignature) as PropertySignature;
303-
propertySignature.modifiers = asNodeArray(modifiers);
304-
propertySignature.name = asName(name);
305-
propertySignature.questionToken = questionToken;
306-
propertySignature.type = type;
307-
propertySignature.initializer = initializer;
308-
return propertySignature;
287+
const node = createSynthesizedNode(SyntaxKind.PropertySignature) as PropertySignature;
288+
node.modifiers = asNodeArray(modifiers);
289+
node.name = asName(name);
290+
node.questionToken = questionToken;
291+
node.type = type;
292+
node.initializer = initializer;
293+
return node;
309294
}
310295

311296
export function updatePropertySignature(node: PropertySignature, modifiers: Modifier[] | undefined, name: PropertyName, questionToken: QuestionToken | undefined, type: TypeNode | undefined, initializer: Expression | undefined) {
@@ -2494,6 +2479,25 @@ namespace ts {
24942479

24952480
/* @internal */
24962481
namespace ts {
2482+
export const nullTransformationContext: TransformationContext = {
2483+
enableEmitNotification: noop,
2484+
enableSubstitution: noop,
2485+
endLexicalEnvironment: () => undefined,
2486+
getCompilerOptions: notImplemented,
2487+
getEmitHost: notImplemented,
2488+
getEmitResolver: notImplemented,
2489+
hoistFunctionDeclaration: noop,
2490+
hoistVariableDeclaration: noop,
2491+
isEmitNotificationEnabled: notImplemented,
2492+
isSubstitutionEnabled: notImplemented,
2493+
onEmitNode: noop,
2494+
onSubstituteNode: notImplemented,
2495+
readEmitHelpers: notImplemented,
2496+
requestEmitHelper: noop,
2497+
resumeLexicalEnvironment: noop,
2498+
startLexicalEnvironment: noop,
2499+
suspendLexicalEnvironment: noop
2500+
};
24972501

24982502
// Compound nodes
24992503

Collapse file

‎src/compiler/types.ts‎

Copy file name to clipboardExpand all lines: src/compiler/types.ts
+13-15Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -576,11 +576,11 @@ namespace ts {
576576
* If the identifier begins with two underscores, this will begin with three.
577577
*/
578578
text: string;
579-
originalKeywordKind?: SyntaxKind; // Original syntaxKind which get set so that we can report an error later
579+
originalKeywordKind?: SyntaxKind; // Original syntaxKind which get set so that we can report an error later
580580
/*@internal*/ autoGenerateKind?: GeneratedIdentifierKind; // Specifies whether to auto-generate the text for an identifier.
581-
/*@internal*/ autoGenerateId?: number; // Ensures unique generated identifiers get unique names, but clones get the same name.
582-
isInJSDocNamespace?: boolean; // if the node is a member in a JSDoc namespace
583-
/*@internal*/ typeArguments?: NodeArray<TypeNode>; // Only defined on synthesized nodes.Though not syntactically valid, used in emitting diagnostics.
581+
/*@internal*/ autoGenerateId?: number; // Ensures unique generated identifiers get unique names, but clones get the same name.
582+
isInJSDocNamespace?: boolean; // if the node is a member in a JSDoc namespace
583+
/*@internal*/ typeArguments?: NodeArray<TypeNode>; // Only defined on synthesized nodes.Though not syntactically valid, used in emitting diagnostics.
584584
}
585585

586586
// Transient identifier node (marked by id === -1)
@@ -2592,14 +2592,14 @@ namespace ts {
25922592
SuppressAnyReturnType = 1 << 8, // If the return type is any-like, don't offer a return type.
25932593

25942594
// Error handling
2595-
allowThisInObjectLiteral = 1 << 10,
2596-
allowQualifedNameInPlaceOfIdentifier = 1 << 11,
2597-
allowTypeParameterInQualifiedName = 1 << 12,
2598-
allowAnonymousIdentifier = 1 << 13,
2599-
allowEmptyUnionOrIntersection = 1 << 14,
2600-
allowEmptyTuple = 1 << 15,
2595+
AllowThisInObjectLiteral = 1 << 10,
2596+
AllowQualifedNameInPlaceOfIdentifier = 1 << 11,
2597+
AllowTypeParameterInQualifiedName = 1 << 12,
2598+
AllowAnonymousIdentifier = 1 << 13,
2599+
AllowEmptyUnionOrIntersection = 1 << 14,
2600+
AllowEmptyTuple = 1 << 15,
26012601

2602-
ignoreErrors = allowThisInObjectLiteral | allowQualifedNameInPlaceOfIdentifier | allowTypeParameterInQualifiedName | allowAnonymousIdentifier | allowEmptyUnionOrIntersection | allowEmptyTuple,
2602+
ignoreErrors = AllowThisInObjectLiteral | AllowQualifedNameInPlaceOfIdentifier | AllowTypeParameterInQualifiedName | AllowAnonymousIdentifier | AllowEmptyUnionOrIntersection | AllowEmptyTuple,
26032603

26042604
// State
26052605
inObjectTypeLiteral = 1 << 20,
@@ -3538,8 +3538,7 @@ namespace ts {
35383538

35393539
export const enum NewLineKind {
35403540
CarriageReturnLineFeed = 0,
3541-
LineFeed = 1,
3542-
None = 2
3541+
LineFeed = 1
35433542
}
35443543

35453544
export interface LineAndCharacter {
@@ -3964,7 +3963,6 @@ namespace ts {
39643963
}
39653964

39663965
export const enum EmitFlags {
3967-
None = 0,
39683966
SingleLine = 1 << 0, // The contents of this node should be emitted on a single line.
39693967
AdviseOnEmitNode = 1 << 1, // The printer should invoke the onEmitNode callback when printing this node.
39703968
NoSubstitution = 1 << 2, // Disables further substitution of an expression.
@@ -4195,7 +4193,7 @@ namespace ts {
41954193
* the identifiers of the source file are used when generating unique names to avoid
41964194
* collisions.
41974195
*/
4198-
printNode(hint: EmitHint, node: Node, sourceFile: SourceFile | undefined): string;
4196+
printNode(hint: EmitHint, node: Node, sourceFile: SourceFile): string;
41994197
/**
42004198
* Prints a source file as-is, without any emit transformations.
42014199
*/
Collapse file

‎src/compiler/utilities.ts‎

Copy file name to clipboardExpand all lines: src/compiler/utilities.ts
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3253,8 +3253,6 @@ namespace ts {
32533253
const lineFeed = "\n";
32543254
export function getNewLineCharacter(options: CompilerOptions | PrinterOptions): string {
32553255
switch (options.newLine) {
3256-
case NewLineKind.None:
3257-
return "";
32583256
case NewLineKind.CarriageReturnLineFeed:
32593257
return carriageReturnLineFeed;
32603258
case NewLineKind.LineFeed:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.