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

Add Path#isInStrictMode #7712

Merged
merged 3 commits into from Apr 11, 2018
Merged

Add Path#isInStrictMode #7712

merged 3 commits into from Apr 11, 2018

Conversation

@jridgewell
Copy link
Member

jridgewell commented Apr 10, 2018

Adds path#isInStrictMode to determine if a parent set strict mode.

@jridgewell jridgewell requested a review from nicolo-ribaudo Apr 10, 2018
@jridgewell jridgewell force-pushed the jridgewell:scope-isstrict branch from 74860a0 to f841535 Apr 10, 2018
@babel-bot

This comment has been minimized.

Copy link
Collaborator

babel-bot commented Apr 11, 2018

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/7548/

@babel-bot

This comment has been minimized.

Copy link
Collaborator

babel-bot commented Apr 11, 2018

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/7547/

if (!path.isProgram() && !path.isFunction()) return false;

let { node } = path;
if (path.isFunction()) node = node.body;

This comment has been minimized.

Copy link
@loganfsmyth

loganfsmyth Apr 11, 2018

Member

Would it be worth handling cases where the path is the function name, or a function parameter? Like technically it could be

function NODE(){"use strict";}
// OR
function fn(NODE){"use strict";}

too. It isn't valid to having function initializers or patterns at least, so we wouldn't have to check too many cases.

This comment has been minimized.

This comment has been minimized.

Copy link
@jridgewell

jridgewell Apr 11, 2018

Author Member

Note: this is directly related to https://github.com/rwaldron/tc39-notes/blob/master/es9/2018-03/mar-22.md#8ic-expand-text-included-in-function-code which we just talked about in last month's meeting. Consensus reached was the id and params are strict if the function body is strict.

This comment has been minimized.

Copy link
@loganfsmyth

loganfsmyth Apr 11, 2018

Member

Oh of course, that's what I get for reviewing while sleepy :P

if (path.isFunction()) node = node.body;

const { directives } = node;
if (!directives) return false;

This comment has been minimized.

Copy link
@loganfsmyth

loganfsmyth Apr 11, 2018

Member

I think in theory this is supposed to always exist unless node isn't BlockStatement (because it is an arrow body expression)? Might be clearer to do

if (!path.isProgram() && !path.isFunction()) return false;

if (path.isArrowFunction() && !path.get("body").isBlockStatement()) return false;

then remove this check?

This comment has been minimized.

Copy link
@jridgewell

jridgewell Apr 11, 2018

Author Member

Yup, that was it. Done.

@jridgewell jridgewell merged commit 7ae724f into babel:master Apr 11, 2018
4 checks passed
4 checks passed
babel/repl REPL preview is available
Details
ci/circleci Your tests passed on CircleCI!
Details
codecov/project 80.78% (target 80%)
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@jridgewell jridgewell deleted the jridgewell:scope-isstrict branch Apr 11, 2018
@lock lock bot added the outdated label Oct 5, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants
You can’t perform that action at this time.