Skip to content
Draft
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/builderState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ namespace ts {
}

/**
* Return true if the file will invalidate all files because it affectes global scope
* Return true if the file will invalidate all files because it affects global scope
*/
function isFileAffectingGlobalScope(sourceFile: SourceFile) {
return containsGlobalScopeAugmentation(sourceFile) ||
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ namespace ts {

/**
* Deduplicates an unsorted array.
* @param array An array to be checked.
* @param equalityComparer An `EqualityComparer` used to determine if two values are duplicates.
* @param comparer An optional `Comparer` used to sort entries before comparison, though the
* result will remain in the original order in `array`.
Expand Down Expand Up @@ -1313,6 +1314,7 @@ namespace ts {
*
* @param left A map-like whose properties should be compared.
* @param right A map-like whose properties should be compared.
* @param equalityComparer A function that compares two values for equality.
*/
export function equalOwnProperties<T>(left: MapLike<T> | undefined, right: MapLike<T> | undefined, equalityComparer: EqualityComparer<T> = equateValues) {
if (left === right) return true;
Expand Down
8 changes: 6 additions & 2 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ namespace ts {
* @param sourceFilesOrTargetSourceFile
* If an array, the full list of source files to emit.
* Else, calls `getSourceFilesToEmit` with the (optional) target source file to determine the list of source files to emit.
* @param forceDtsEmit whether to always generate declaration files.
* @param onlyBuildInfo Whether to build only the target file.
* @param includeBuildInfo Whether to include the built files in the result.
*/
export function forEachEmittedFile<T>(
host: EmitHost, action: (emitFileNames: EmitFileNames, sourceFileOrBundle: SourceFile | Bundle | undefined) => T,
Expand Down Expand Up @@ -1084,7 +1087,7 @@ namespace ts {
bundleFileInfo.sources.prologues = prologues;
}

// Store helpes
// Store helps
const helpers = getHelpersFromBundledSourceFiles(bundle);
if (helpers) {
if (!bundleFileInfo.sources) bundleFileInfo.sources = {};
Expand Down Expand Up @@ -5802,7 +5805,8 @@ namespace ts {
*
* @param node The node containing the token.
* @param token The token to emit.
* @param tokenStartPos The start pos of the token.
* @param writer The operation of EmitTextWriter.
* @param tokenPos The start pos of the token.
* @param emitCallback The callback used to emit the token.
*/
function emitTokenWithSourceMap(node: Node | undefined, token: SyntaxKind, writer: (s: string) => void, tokenPos: number, emitCallback: (token: SyntaxKind, writer: (s: string) => void, tokenStartPos: number) => number) {
Expand Down
19 changes: 8 additions & 11 deletions src/compiler/factory/nodeFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace ts {
const parenthesizerRules = memoize(() => flags & NodeFactoryFlags.NoParenthesizerRules ? nullParenthesizerRules : createParenthesizerRules(factory));
const converters = memoize(() => flags & NodeFactoryFlags.NoNodeConverters ? nullNodeConverters : createNodeConverters(factory));

// lazy initializaton of common operator factories
// lazy initialization of common operator factories
const getBinaryCreateFunction = memoizeOne((operator: BinaryOperator) => (left: Expression, right: Expression) => createBinaryExpression(left, operator, right));
const getPrefixUnaryCreateFunction = memoizeOne((operator: PrefixUnaryOperator) => (operand: Expression) => createPrefixUnaryExpression(operator, operand));
const getPostfixUnaryCreateFunction = memoizeOne((operator: PostfixUnaryOperator) => (operand: Expression) => createPostfixUnaryExpression(operand, operator));
Expand Down Expand Up @@ -2314,7 +2314,7 @@ namespace ts {
// @api
function createArrayLiteralExpression(elements?: readonly Expression[], multiLine?: boolean) {
const node = createBaseExpression<ArrayLiteralExpression>(SyntaxKind.ArrayLiteralExpression);
// Ensure we add a trailing comma for something like `[NumericLiteral(1), NumericLiteral(2), OmittedExpresion]` so that
// Ensure we add a trailing comma for something like `[NumericLiteral(1), NumericLiteral(2), OmittedExpression]` so that
// we end up with `[1, 2, ,]` instead of `[1, 2, ]` otherwise the `OmittedExpression` will just end up being treated like
// a trailing comma.
const lastElement = elements && lastOrUndefined(elements);
Expand Down Expand Up @@ -5744,11 +5744,7 @@ namespace ts {
case SyntaxKind.StringLiteral:
return false;
case SyntaxKind.ArrayLiteralExpression:
const elements = (target as ArrayLiteralExpression).elements;
if (elements.length === 0) {
return false;
}
return true;
return (target as ArrayLiteralExpression).elements.length > 0;
case SyntaxKind.ObjectLiteralExpression:
return (target as ObjectLiteralExpression).properties.length > 0;
default:
Expand Down Expand Up @@ -5878,7 +5874,7 @@ namespace ts {
/**
* Gets the internal name of a declaration. This is primarily used for declarations that can be
* referred to by name in the body of an ES5 class function body. An internal name will *never*
* be prefixed with an module or namespace export modifier like "exports." when emitted as an
* be prefixed with a module or namespace export modifier like "exports." when emitted as an
* expression. An internal name will also *never* be renamed due to a collision with a block
* scoped variable.
*
Expand All @@ -5893,7 +5889,7 @@ namespace ts {
/**
* Gets the local name of a declaration. This is primarily used for declarations that can be
* referred to by name in the declaration's immediate scope (classes, enums, namespaces). A
* local name will *never* be prefixed with an module or namespace export modifier like
* local name will *never* be prefixed with a module or namespace export modifier like
* "exports." when emitted as an expression.
*
* @param node The declaration.
Expand All @@ -5907,7 +5903,7 @@ namespace ts {
/**
* Gets the export name of a declaration. This is primarily used for declarations that can be
* referred to by name in the declaration's immediate scope (classes, enums, namespaces). An
* export name will *always* be prefixed with an module or namespace export modifier like
* export name will *always* be prefixed with a module or namespace export modifier like
* `"exports."` when emitted as an expression if the name points to an exported symbol.
*
* @param node The declaration.
Expand Down Expand Up @@ -5950,7 +5946,7 @@ namespace ts {
/**
* Gets the exported name of a declaration for use in expressions.
*
* An exported name will *always* be prefixed with an module or namespace export modifier like
* An exported name will *always* be prefixed with a module or namespace export modifier like
* "exports." if the name points to an exported symbol.
*
* @param ns The namespace identifier.
Expand Down Expand Up @@ -6022,6 +6018,7 @@ namespace ts {
* @param target result statements array
* @param statementOffset The offset at which to begin the copy.
* @param visitor Optional callback used to visit any custom prologue directives.
* @param filter the function that determines whether a statement meets the condition specified
*/
function copyCustomPrologue(source: readonly Statement[], target: Push<Statement>, statementOffset: number, visitor?: (node: Node) => VisitResult<Node>, filter?: (node: Node) => boolean): number;
function copyCustomPrologue(source: readonly Statement[], target: Push<Statement>, statementOffset: number | undefined, visitor?: (node: Node) => VisitResult<Node>, filter?: (node: Node) => boolean): number | undefined;
Expand Down
27 changes: 13 additions & 14 deletions src/compiler/factory/parenthesizerRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ namespace ts {
* @param operand The operand for the BinaryExpression.
* @param isLeftSideOfBinary A value indicating whether the operand is the left side of the
* BinaryExpression.
* @param leftOperand The left operand if {@link operand} is the right side of the
* BinaryExpression and {@link isLeftSideOfBinary} is false
*/
function binaryOperandNeedsParentheses(binaryOperator: SyntaxKind, operand: Expression, isLeftSideOfBinary: boolean, leftOperand: Expression | undefined) {
// If the operand has lower precedence, then it needs to be parenthesized to preserve the
Expand Down Expand Up @@ -91,13 +93,9 @@ namespace ts {
case Comparison.LessThan:
// If the operand is the right side of a right-associative binary operation
// and is a yield expression, then we do not need parentheses.
if (!isLeftSideOfBinary
return !(!isLeftSideOfBinary
&& binaryOperatorAssociativity === Associativity.Right
&& operand.kind === SyntaxKind.YieldExpression) {
return false;
}

return true;
&& operand.kind === SyntaxKind.YieldExpression);

case Comparison.GreaterThan:
return false;
Expand Down Expand Up @@ -216,7 +214,8 @@ namespace ts {
* @param operand The operand for the BinaryExpression.
* @param isLeftSideOfBinary A value indicating whether the operand is the left side of the
* BinaryExpression.
*/
* @param leftOperand The left operand if {@link operand} is the right side of the
* BinaryExpression and {@link isLeftSideOfBinary} is false */
function parenthesizeBinaryOperand(binaryOperator: SyntaxKind, operand: Expression, isLeftSideOfBinary: boolean, leftOperand?: Expression) {
const skipped = skipPartiallyEmittedExpressions(operand);

Expand Down Expand Up @@ -324,17 +323,17 @@ namespace ts {
return expression as LeftHandSideExpression;
}

// TODO(rbuckton): Verifiy whether `setTextRange` is needed.
// TODO(rbuckton): Verify whether `setTextRange` is needed.
return setTextRange(factory.createParenthesizedExpression(expression), expression);
}

function parenthesizeOperandOfPostfixUnary(operand: Expression): LeftHandSideExpression {
// TODO(rbuckton): Verifiy whether `setTextRange` is needed.
// TODO(rbuckton): Verify whether `setTextRange` is needed.
return isLeftHandSideExpression(operand) ? operand : setTextRange(factory.createParenthesizedExpression(operand), operand);
}

function parenthesizeOperandOfPrefixUnary(operand: Expression): UnaryExpression {
// TODO(rbuckton): Verifiy whether `setTextRange` is needed.
// TODO(rbuckton): Verify whether `setTextRange` is needed.
return isUnaryExpression(operand) ? operand : setTextRange(factory.createParenthesizedExpression(operand), operand);
}

Expand All @@ -347,7 +346,7 @@ namespace ts {
const emittedExpression = skipPartiallyEmittedExpressions(expression);
const expressionPrecedence = getExpressionPrecedence(emittedExpression);
const commaPrecedence = getOperatorPrecedence(SyntaxKind.BinaryExpression, SyntaxKind.CommaToken);
// TODO(rbuckton): Verifiy whether `setTextRange` is needed.
// TODO(rbuckton): Verify whether `setTextRange` is needed.
return expressionPrecedence > commaPrecedence ? expression : setTextRange(factory.createParenthesizedExpression(expression), expression);
}

Expand All @@ -357,7 +356,7 @@ namespace ts {
const callee = emittedExpression.expression;
const kind = skipPartiallyEmittedExpressions(callee).kind;
if (kind === SyntaxKind.FunctionExpression || kind === SyntaxKind.ArrowFunction) {
// TODO(rbuckton): Verifiy whether `setTextRange` is needed.
// TODO(rbuckton): Verify whether `setTextRange` is needed.
const updated = factory.updateCallExpression(
emittedExpression,
setTextRange(factory.createParenthesizedExpression(callee), callee),
Expand All @@ -370,7 +369,7 @@ namespace ts {

const leftmostExpressionKind = getLeftmostExpression(emittedExpression, /*stopAtCallExpressions*/ false).kind;
if (leftmostExpressionKind === SyntaxKind.ObjectLiteralExpression || leftmostExpressionKind === SyntaxKind.FunctionExpression) {
// TODO(rbuckton): Verifiy whether `setTextRange` is needed.
// TODO(rbuckton): Verify whether `setTextRange` is needed.
return setTextRange(factory.createParenthesizedExpression(expression), expression);
}

Expand All @@ -381,7 +380,7 @@ namespace ts {
function parenthesizeConciseBodyOfArrowFunction(body: ConciseBody): ConciseBody;
function parenthesizeConciseBodyOfArrowFunction(body: ConciseBody): ConciseBody {
if (!isBlock(body) && (isCommaSequence(body) || getLeftmostExpression(body, /*stopAtCallExpressions*/ false).kind === SyntaxKind.ObjectLiteralExpression)) {
// TODO(rbuckton): Verifiy whether `setTextRange` is needed.
// TODO(rbuckton): Verify whether `setTextRange` is needed.
return setTextRange(factory.createParenthesizedExpression(body), body);
}

Expand Down
3 changes: 3 additions & 0 deletions src/compiler/factory/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ namespace ts {
* @param factory {@link NodeFactory} used to create the expanded representation.
* @param node The original prefix or postfix unary node.
* @param expression The expression to use as the value to increment or decrement
* @param recordTempVariable A callback which reference to `hoistVariableDeclaration` from a `TransformationContext` used to record the temporary variable name.
* @param resultVariable A temporary variable in which to store the result. Pass `undefined` if the result is discarded, or if the value of `<temp>` is the expected result.
*/
export function expandPreOrPostfixIncrementOrDecrementExpression(factory: NodeFactory, node: PrefixUnaryExpression | PostfixUnaryExpression, expression: Expression, recordTempVariable: (node: Identifier) => void, resultVariable: Identifier | undefined) {
Expand Down Expand Up @@ -1161,6 +1162,7 @@ namespace ts {
* Creates a state machine that walks a `BinaryExpression` using the heap to reduce call-stack depth on a large tree.
* @param onEnter Callback evaluated when entering a `BinaryExpression`. Returns new user-defined state to associate with the node while walking.
* @param onLeft Callback evaluated when walking the left side of a `BinaryExpression`. Return a `BinaryExpression` to continue walking, or `void` to advance to the right side.
* @param onOperator Callback evaluated when walking the operator of a `BinaryExpression`.
* @param onRight Callback evaluated when walking the right side of a `BinaryExpression`. Return a `BinaryExpression` to continue walking, or `void` to advance to the end of the node.
* @param onExit Callback evaluated when exiting a `BinaryExpression`. The result returned will either be folded into the parent's state, or returned from the walker if at the top frame.
* @param foldState Callback evaluated when the result from a nested `onExit` should be folded into the state of that node's parent.
Expand All @@ -1178,6 +1180,7 @@ namespace ts {
* Creates a state machine that walks a `BinaryExpression` using the heap to reduce call-stack depth on a large tree.
* @param onEnter Callback evaluated when entering a `BinaryExpression`. Returns new user-defined state to associate with the node while walking.
* @param onLeft Callback evaluated when walking the left side of a `BinaryExpression`. Return a `BinaryExpression` to continue walking, or `void` to advance to the right side.
* @param onOperator Callback evaluated when walking the operator of a `BinaryExpression`.
* @param onRight Callback evaluated when walking the right side of a `BinaryExpression`. Return a `BinaryExpression` to continue walking, or `void` to advance to the end of the node.
* @param onExit Callback evaluated when exiting a `BinaryExpression`. The result returned will either be folded into the parent's state, or returned from the walker if at the top frame.
* @param foldState Callback evaluated when the result from a nested `onExit` should be folded into the state of that node's parent.
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/moduleSpecifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ namespace ts.moduleSpecifiers {
// Module specifier priority:
// 1. "Bare package specifiers" (e.g. "@foo/bar") resulting from a path through node_modules to a package.json's "types" entry
// 2. Specifiers generated using "paths" from tsconfig
// 3. Non-relative specfiers resulting from a path through node_modules (e.g. "@foo/bar/path/to/file")
// 3. Non-relative specifiers resulting from a path through node_modules (e.g. "@foo/bar/path/to/file")
// 4. Relative paths
let nodeModulesSpecifiers: string[] | undefined;
let pathsSpecifiers: string[] | undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/sourcemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ namespace ts {
}

// Sometimes tools can see the following line as a source mapping url comment, so we mangle it a bit (the [M])
const sourceMapCommentRegExp = /^\/\/[@#] source[M]appingURL=(.+)\r?\n?$/;
const sourceMapCommentRegExp = /^\/\/[@#] sourceMappingURL=(.+)\r?\n?$/;

const whitespaceOrMapCommentRegExp = /^\s*(\/\/[@#] .*)?$/;

Expand Down
4 changes: 2 additions & 2 deletions src/compiler/symbolWalker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace ts {
visitedTypes[type.id] = type;

// Reuse visitSymbol to visit the type's symbol,
// but be sure to bail on recuring into the type if accept declines the symbol.
// but be sure to bail on recurring into the type if accept declines the symbol.
const shouldBail = visitSymbol(type.symbol);
if (shouldBail) return;

Expand Down Expand Up @@ -187,4 +187,4 @@ namespace ts {
}
}
}
}
}
4 changes: 2 additions & 2 deletions src/compiler/sys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1521,7 +1521,7 @@ namespace ts {
if (platform === "win32" || platform === "win64") {
return false;
}
// If this file exists under a different case, we must be case-insensitve.
// If this file exists under a different case, we must be case-insensitive.
return !fileExists(swapCase(__filename));
}

Expand All @@ -1541,7 +1541,7 @@ namespace ts {
};

function fileChanged(curr: any, prev: any) {
// previous event kind check is to ensure we recongnize the file as previously also missing when it is restored or renamed twice (that is it disappears and reappears)
// previous event kind check is to ensure we recognize the file as previously also missing when it is restored or renamed twice (that is it disappears and reappears)
// In such case, prevTime returned is same as prev time of event when file was deleted as per node documentation
const isPreviouslyDeleted = +prev.mtime === 0 || eventKind === FileWatcherEventKind.Deleted;
if (+curr.mtime === 0) {
Expand Down
Loading