Skip to content

Remove _this, _super, and _newTarget name conflict errors#22890

Merged
weswigham merged 13 commits into
microsoft:masterfrom
weswigham:remove-conflict-errors
Mar 31, 2018
Merged

Remove _this, _super, and _newTarget name conflict errors#22890
weswigham merged 13 commits into
microsoft:masterfrom
weswigham:remove-conflict-errors

Conversation

@weswigham
Copy link
Copy Markdown
Member

Instead of issuing an error, we just rename the variable we emit. This is a followup to my comment on #22886.

Copy link
Copy Markdown
Contributor

@mhegazy mhegazy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rbuckton comments?

@mhegazy
Copy link
Copy Markdown
Contributor

mhegazy commented Mar 29, 2018

ping @rbuckton

Comment thread src/compiler/types.ts Outdated
Unique = 3, // Unique name based on the 'text' property.
Node = 4, // Unique name based on the node in the 'original' property.
OptimisticUnique = 5, // Unique name based on the 'text' property, first instance won't use '_#' if there's no conflict
FileLevel = 6, // Optimistic unique name based on the 'text' property, first instance won't use '_#' if there's no conflict, using only the file identifiers list
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both FileLevel and OptimisticUnique seem more like flags than kinds, since they just augment the behavior of makeUniqueName in emitter.ts.

Comment thread src/compiler/emitter.ts Outdated
writer(helper);
}
else {
writer(helper({
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason you allocate an object just to pass a callback? Could this not just be the callback itself?

Comment thread src/compiler/emitter.ts Outdated
return helpersEmitted;
}

function writeHelper(writer: (text: string) => void, helper: EmitHelper["text"], makeUniqueName: UniqueNameHandler) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of indirection going on here, and writeHelper only seems to be used once. It seems like it would be better to just keep this inline in emitHelpers rather than add more complexity through even more callbacks and indirection.

Comment thread src/compiler/emitter.ts Outdated
}
else {
writer(helper({
makeFileLevelUniqueName: name => makeUniqueName(name, isFileLevelUniqueName, /*optimistic*/ true),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be pulled out into a function to avoid allocating a new function object every time this is called.

Comment thread src/compiler/emitter.ts Outdated
}

function emitHelpers(node: Node, writeLines: (text: string) => void) {
function emitHelpers(node: Node, writeLines: (text: string) => void, makeUniqueName: UniqueNameHandler) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to just consider moving this into the printer.

@weswigham
Copy link
Copy Markdown
Member Author

@rbuckton Done.

Comment thread src/compiler/types.ts Outdated
newLine?: NewLineKind;
omitTrailingSemicolon?: boolean;
noEmitHelpers?: boolean;
module?: CompilerOptions["module"];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should probably be /*@internal*/.

@weswigham weswigham merged commit 9b558f9 into microsoft:master Mar 31, 2018
@weswigham weswigham deleted the remove-conflict-errors branch March 31, 2018 01:37
@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants