Skip to content

Commit d24112d

Browse files
committed
Remove preprinter, add parenthesizer callback to emit
1 parent 7c10135 commit d24112d

File tree

7 files changed

+3711
-4767
lines changed

7 files changed

+3711
-4767
lines changed

src/compiler/emitter.ts

Lines changed: 3684 additions & 4745 deletions
Large diffs are not rendered by default.

src/compiler/factory/nodeFactory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2139,7 +2139,7 @@ namespace ts {
21392139
/*decorators*/ undefined,
21402140
/*modifiers*/ undefined,
21412141
name,
2142-
initializer
2142+
initializer && parenthesizerRules().parenthesizeExpressionForDisallowedComma(initializer)
21432143
);
21442144
node.propertyName = asName(propertyName);
21452145
node.dotDotDotToken = dotDotDotToken;

src/compiler/factory/parenthesizerRules.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ namespace ts {
210210
return parenthesizeBinaryOperand(binaryOperator, leftSide, /*isLeftSideOfBinary*/ true);
211211
}
212212

213-
function parenthesizeRightSideOfBinary(binaryOperator: SyntaxKind, leftSide: Expression, rightSide: Expression): Expression {
213+
function parenthesizeRightSideOfBinary(binaryOperator: SyntaxKind, leftSide: Expression | undefined, rightSide: Expression): Expression {
214214
return parenthesizeBinaryOperand(binaryOperator, rightSide, /*isLeftSideOfBinary*/ false, leftSide);
215215
}
216216

@@ -352,6 +352,8 @@ namespace ts {
352352
return expression;
353353
}
354354

355+
function parenthesizeConciseBodyOfArrowFunction(body: Expression): Expression;
356+
function parenthesizeConciseBodyOfArrowFunction(body: ConciseBody): ConciseBody;
355357
function parenthesizeConciseBodyOfArrowFunction(body: ConciseBody): ConciseBody {
356358
if (!isBlock(body) && (isCommaSequence(body) || getLeftmostExpression(body, /*stopAtCallExpressions*/ false).kind === SyntaxKind.ObjectLiteralExpression)) {
357359
// TODO(rbuckton): Verifiy whether `setTextRange` is needed.

src/compiler/transformer.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -562,31 +562,31 @@ namespace ts {
562562
}
563563

564564
export const nullTransformationContext: TransformationContext = {
565-
get factory() { return factory; },
566-
enableEmitNotification: noop,
567-
enableSubstitution: noop,
568-
endLexicalEnvironment: returnUndefined,
565+
factory,
569566
getCompilerOptions: () => ({}),
570-
getEmitHost: notImplemented,
571567
getEmitResolver: notImplemented,
568+
getEmitHost: notImplemented,
572569
getEmitHelperFactory: notImplemented,
570+
startLexicalEnvironment: noop,
571+
resumeLexicalEnvironment: noop,
572+
suspendLexicalEnvironment: noop,
573+
endLexicalEnvironment: returnUndefined,
573574
setLexicalEnvironmentFlags: noop,
574575
getLexicalEnvironmentFlags: () => 0,
575-
hoistFunctionDeclaration: noop,
576576
hoistVariableDeclaration: noop,
577+
hoistFunctionDeclaration: noop,
577578
addInitializationStatement: noop,
578-
isEmitNotificationEnabled: notImplemented,
579-
isSubstitutionEnabled: notImplemented,
580-
onEmitNode: noop,
581-
onSubstituteNode: notImplemented,
582-
readEmitHelpers: notImplemented,
583-
requestEmitHelper: noop,
584-
resumeLexicalEnvironment: noop,
585-
startLexicalEnvironment: noop,
586-
suspendLexicalEnvironment: noop,
587-
addDiagnostic: noop,
588579
startBlockScope: noop,
589580
endBlockScope: returnUndefined,
590-
addBlockScopedVariable: noop
581+
addBlockScopedVariable: noop,
582+
requestEmitHelper: noop,
583+
readEmitHelpers: notImplemented,
584+
enableSubstitution: noop,
585+
enableEmitNotification: noop,
586+
isSubstitutionEnabled: notImplemented,
587+
isEmitNotificationEnabled: notImplemented,
588+
onSubstituteNode: noEmitSubstitution,
589+
onEmitNode: noEmitNotification,
590+
addDiagnostic: noop,
591591
};
592592
}

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6798,6 +6798,7 @@ namespace ts {
67986798
parenthesizeExpressionsOfCommaDelimitedList(elements: readonly Expression[]): NodeArray<Expression>;
67996799
parenthesizeExpressionForDisallowedComma(expression: Expression): Expression;
68006800
parenthesizeExpressionOfExpressionStatement(expression: Expression): Expression;
6801+
parenthesizeConciseBodyOfArrowFunction(body: Expression): Expression;
68016802
parenthesizeConciseBodyOfArrowFunction(body: ConciseBody): ConciseBody;
68026803
parenthesizeMemberOfConditionalType(member: TypeNode): TypeNode;
68036804
parenthesizeMemberOfElementType(member: TypeNode): TypeNode;

tests/baselines/reference/inlineJsxFactoryDeclarationsLocalTypes.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,6 @@ var _brokenTree = (0, renderer_1.dom)(component_1.MySFC, { x: 1, y: 2 },
161161
(0, renderer_1.dom)(component_1.MyClass, { x: 3, y: 4 }),
162162
(0, renderer_1.dom)(component_1.MyClass, { x: 5, y: 6 }));
163163
// Should fail, nondom isn't allowed as children of dom
164-
var _brokenTree2 = (0, renderer_1.dom)(DOMSFC, { x: 1, y: 2 }, component_1.tree, component_1.tree);
164+
var _brokenTree2 = (0, renderer_1.dom)(DOMSFC, { x: 1, y: 2 },
165+
component_1.tree,
166+
component_1.tree);

tests/baselines/reference/jsxCheckJsxNoTypeArgumentsAllowed.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ let x = <MyComp<Prop> a={10} b="hi" />; // error, no type arguments in js
2323
exports.__esModule = true;
2424
var component_1 = require("./component");
2525
var React = require("react");
26-
var x = (<component_1.MyComp />, <Prop> a={10} b="hi" />; // error, no type arguments in js
27-
</>);
26+
var x = <component_1.MyComp />, <Prop> a={10} b="hi" />; // error, no type arguments in js
27+
</>;

0 commit comments

Comments
 (0)