Skip to content
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

Extract source map generation logic out of the emitter. #5780

Merged
merged 8 commits into from Nov 30, 2015

Conversation

rbuckton
Copy link
Member

Supports #5595.

@@ -2414,6 +2414,27 @@ namespace ts {
return output;
}

export const stringify: (value: any) => string = JSON && JSON.stringify ? JSON.stringify : function stringify(value: any): string {
/* tslint:disable:no-null */
return value == null ? "null"
Copy link
Member

Choose a reason for hiding this comment

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

Should use === when comparing with null - as written this lumps undefined with null. If value is undefined, JSON.stringify should return undefined. A key with an undefined value should be omitted, but an array with undefined slots should have those slots serialized as null (as this does). Presently, a map with undefined valued keys gets encoded with null values, since Object.prototype.hasOwnProperty.call({x: undefined}, 'x') returns true.

Copy link
Member

Choose a reason for hiding this comment

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

Wait, no, nevermind, stringifyProperty has a guard for undefined. That was confusing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually it should be value === null, as that's how I have it in the experimentalTransforms branch. This was a typo introduced while trying to work out how to disable a tslint rule :)

Copy link
Member

Choose a reason for hiding this comment

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

undefined does get stringified to "null" as expected by the last case, too. :3

@weswigham
Copy link
Member

👍

export function getNullSourceMapWriter(): SourceMapWriter {
if (nullSourceMapWriter === undefined) {
nullSourceMapWriter = {
getSourceMapData: nop,
Copy link
Contributor

Choose a reason for hiding this comment

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

this needs to be checked, but AFAIR calling vararg function with different number of arguments is not a very good pattern for V8. When source map code was written initially it has the same shape but then it was rewritten so each nop function has the same number of arguments with the corresponding method in the interface.

Copy link
Member

Choose a reason for hiding this comment

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

@vladima is right. We had seen perf impact of not using same number of arguments in the no-op functions

Copy link
Member Author

Choose a reason for hiding this comment

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

I can add stubs for these, though when I ran the performance tests the cost looked negligible (and the performance tests don't include source maps, so they would be hitting this case). I do wonder if v8 has any optimizations for the Function.prototype primordial. If I see a major difference I'll push up a new commit.

Copy link
Member Author

Choose a reason for hiding this comment

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

There does seem to be a small improvement, so I'm adding the stubs.

@sandersn
Copy link
Member

👍

@mhegazy
Copy link
Contributor

mhegazy commented Nov 26, 2015

👍

rbuckton added a commit that referenced this pull request Nov 30, 2015
Extract source map generation logic out of the emitter.
@rbuckton rbuckton merged commit 266600d into master Nov 30, 2015
@rbuckton rbuckton deleted the extractSourceMaps branch December 1, 2015 23:04
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 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.

None yet

7 participants