Skip to content

JS: correctly treat ES2015 modules as being in strict-mode in the JavaScript extractor#4092

Merged
codeql-ci merged 3 commits intogithub:mainfrom
erik-krogh:strictExtractor
Aug 19, 2020
Merged

JS: correctly treat ES2015 modules as being in strict-mode in the JavaScript extractor#4092
codeql-ci merged 3 commits intogithub:mainfrom
erik-krogh:strictExtractor

Conversation

@erik-krogh
Copy link
Contributor

I was trying to understand the QL/Java code for module detection, and I encountered this bug.

The extractor would always overwrite isStrict with the result from hasUseStrict(nd.getBody()).
So whether the file was a ES2015 module would be ignored while extracting.

The prevIsStrict variable should not be necessary (because Program is the top-most node visited), but I added it anyway because I feel it is good style.

The only impact this has in the extractor is function/block scopes for functions, so I added a test for that.

@erik-krogh erik-krogh added the JS label Aug 18, 2020
@erik-krogh erik-krogh requested a review from a team as a code owner August 18, 2020 08:21
Copy link
Contributor

@esbena esbena left a comment

Choose a reason for hiding this comment

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

LGTM. Modulo the missing extractor version bump.

return 3;
}
}
return foo(); // `foo` is not defined, because we are in strict-mode.
Copy link
Contributor

Choose a reason for hiding this comment

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

sanity check: this is the only test that changes output due to the extractor fixup, right? The two other tests remain unchanged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes.

esbena
esbena previously approved these changes Aug 18, 2020
Copy link
Contributor

@esbena esbena left a comment

Choose a reason for hiding this comment

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

Lets land this first, and rebase the other extractor PR on top of that.

@erik-krogh
Copy link
Contributor Author

@esbena can I get a final approve?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments