Skip to content

Module code should be strict mode code #5316

@svkurowski

Description

@svkurowski

According to the standard:

Module code is always strict mode code.

React-Native enables the ES 2015 Modules Babel transformations (see here). However, modules in React Native don't have strict mode code by default.

To reproduce:

react-native init StrictModulesTest
cd StrictModulesTest
cat <<EOT > foo.js
export default function foo() {
delete Object.prototype;
}
EOT

Then insert into index.ios.js or index.android.js:

import foo from './foo';
foo();

and run the app.
Expected: Error Unable to delete property..
Actual: App is showing as normal.

Now insert "use strict"; at the beginning of foo.js and the error shows up.

Note that babel-plugin-transform-es2015-modules-commonjs inserts the "use strict"; automatically, so in some way React-Native must disable this behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions