Skip to content

Commit

Permalink
feat(compiler): use JavaScript strict mode (#4466)
Browse files Browse the repository at this point in the history
Closes #2527

Compiler now puts [`"use strict";`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode) at the top of each generated JS.


## Checklist

- [x] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted)
- [x] Description explains motivation and solution
- [x] Tests added (always)
- [ ] Docs updated (only required for features)
- [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing

*By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
  • Loading branch information
exoego authored Oct 12, 2023
1 parent 471f187 commit 6209397
Show file tree
Hide file tree
Showing 337 changed files with 1,157 additions and 80 deletions.
3 changes: 3 additions & 0 deletions libs/wingc/src/jsify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ impl<'a> JSifier<'a> {
let is_entrypoint = is_entrypoint_file(source_path);
let is_directory = source_path.is_dir();

output.line("\"use strict\";");

if is_entrypoint {
output.line(format!("const {} = require('{}');", STDLIB, STDLIB_MODULE));
output.line(format!(
Expand Down Expand Up @@ -1355,6 +1357,7 @@ impl<'a> JSifier<'a> {
Default::default()
};

code.line("\"use strict\";");
code.open(format!("module.exports = function({{ {inputs} }}) {{"));
code.add_code(inflight_class_code);
code.line(format!("return {name};"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ source: libs/wingc/src/jsify/tests.rs
## inflight.$Closure1-1.js

```js
"use strict";
module.exports = function({ $_y_at_0__, $x_length }) {
class $Closure1 {
constructor({ }) {
Expand All @@ -37,6 +38,7 @@ module.exports = function({ $_y_at_0__, $x_length }) {
## preflight.js

```js
"use strict";
const $stdlib = require('@winglang/sdk');
const $plugins = ((s) => !s ? [] : s.split(';'))(process.env.WING_PLUGIN_PATHS);
const $outdir = process.env.WING_SYNTH_DIR ?? ".";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ source: libs/wingc/src/jsify/tests.rs
## inflight.$Closure1-1.js

```js
"use strict";
module.exports = function({ $s_length }) {
class $Closure1 {
constructor({ }) {
Expand All @@ -34,6 +35,7 @@ module.exports = function({ $s_length }) {
## preflight.js

```js
"use strict";
const $stdlib = require('@winglang/sdk');
const $plugins = ((s) => !s ? [] : s.split(';'))(process.env.WING_PLUGIN_PATHS);
const $outdir = process.env.WING_SYNTH_DIR ?? ".";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ source: libs/wingc/src/jsify/tests.rs
## inflight.$Closure1-1.js

```js
"use strict";
module.exports = function({ $_s___hello___length }) {
class $Closure1 {
constructor({ }) {
Expand All @@ -34,6 +35,7 @@ module.exports = function({ $_s___hello___length }) {
## preflight.js

```js
"use strict";
const $stdlib = require('@winglang/sdk');
const $plugins = ((s) => !s ? [] : s.split(';'))(process.env.WING_PLUGIN_PATHS);
const $outdir = process.env.WING_SYNTH_DIR ?? ".";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ source: libs/wingc/src/jsify/tests.rs
## inflight.Base-1.js

```js
"use strict";
module.exports = function({ $x }) {
class Base {
constructor({ }) {
Expand All @@ -39,6 +40,7 @@ module.exports = function({ $x }) {
## inflight.Derived-1.js

```js
"use strict";
module.exports = function({ $Base }) {
class Derived extends $Base {
constructor({ }) {
Expand All @@ -55,6 +57,7 @@ module.exports = function({ $Base }) {
## preflight.js

```js
"use strict";
const $stdlib = require('@winglang/sdk');
const $plugins = ((s) => !s ? [] : s.split(';'))(process.env.WING_PLUGIN_PATHS);
const $outdir = process.env.WING_SYNTH_DIR ?? ".";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ source: libs/wingc/src/jsify/tests.rs
## inflight.Base-1.js

```js
"use strict";
module.exports = function({ }) {
class Base {
constructor({ }) {
Expand All @@ -36,6 +37,7 @@ module.exports = function({ }) {
## inflight.Derived-1.js

```js
"use strict";
module.exports = function({ $Base }) {
class Derived extends $Base {
constructor({ }) {
Expand All @@ -49,6 +51,7 @@ module.exports = function({ $Base }) {
## preflight.js

```js
"use strict";
const $stdlib = require('@winglang/sdk');
const $plugins = ((s) => !s ? [] : s.split(';'))(process.env.WING_PLUGIN_PATHS);
const $outdir = process.env.WING_SYNTH_DIR ?? ".";
Expand Down
3 changes: 3 additions & 0 deletions libs/wingc/src/jsify/snapshots/base_class_lift_indirect.snap
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ source: libs/wingc/src/jsify/tests.rs
## inflight.Base-1.js

```js
"use strict";
module.exports = function({ }) {
class Base {
constructor({ $this_b }) {
Expand All @@ -47,6 +48,7 @@ module.exports = function({ }) {
## inflight.Derived-1.js

```js
"use strict";
module.exports = function({ $Base }) {
class Derived extends $Base {
constructor({ $this_b }) {
Expand All @@ -63,6 +65,7 @@ module.exports = function({ $Base }) {
## preflight.js

```js
"use strict";
const $stdlib = require('@winglang/sdk');
const $plugins = ((s) => !s ? [] : s.split(';'))(process.env.WING_PLUGIN_PATHS);
const $outdir = process.env.WING_SYNTH_DIR ?? ".";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ source: libs/wingc/src/jsify/tests.rs
## inflight.Base-1.js

```js
"use strict";
module.exports = function({ }) {
class Base {
constructor({ }) {
Expand All @@ -44,6 +45,7 @@ module.exports = function({ }) {
## inflight.Derived-1.js

```js
"use strict";
module.exports = function({ $Base }) {
class Derived extends $Base {
constructor({ }) {
Expand All @@ -64,6 +66,7 @@ module.exports = function({ $Base }) {
## preflight.js

```js
"use strict";
const $stdlib = require('@winglang/sdk');
const $plugins = ((s) => !s ? [] : s.split(';'))(process.env.WING_PLUGIN_PATHS);
const $outdir = process.env.WING_SYNTH_DIR ?? ".";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ source: libs/wingc/src/jsify/tests.rs
## inflight.Base-1.js

```js
"use strict";
module.exports = function({ }) {
class Base {
constructor({ }) {
Expand All @@ -41,6 +42,7 @@ module.exports = function({ }) {
## inflight.Derived-1.js

```js
"use strict";
module.exports = function({ $Base }) {
class Derived extends $Base {
constructor({ }) {
Expand All @@ -54,6 +56,7 @@ module.exports = function({ $Base }) {
## preflight.js

```js
"use strict";
const $stdlib = require('@winglang/sdk');
const $plugins = ((s) => !s ? [] : s.split(';'))(process.env.WING_PLUGIN_PATHS);
const $outdir = process.env.WING_SYNTH_DIR ?? ".";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ source: libs/wingc/src/jsify/tests.rs
## inflight.Base-1.js

```js
"use strict";
module.exports = function({ }) {
class Base {
constructor({ }) {
Expand All @@ -37,6 +38,7 @@ module.exports = function({ }) {
## inflight.Derived-1.js

```js
"use strict";
module.exports = function({ $Base }) {
class Derived extends $Base {
constructor({ $this_b }) {
Expand All @@ -54,6 +56,7 @@ module.exports = function({ $Base }) {
## preflight.js

```js
"use strict";
const $stdlib = require('@winglang/sdk');
const $plugins = ((s) => !s ? [] : s.split(';'))(process.env.WING_PLUGIN_PATHS);
const $outdir = process.env.WING_SYNTH_DIR ?? ".";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ source: libs/wingc/src/jsify/tests.rs
## inflight.Base-1.js

```js
"use strict";
module.exports = function({ }) {
class Base {
constructor({ }) {
Expand All @@ -37,6 +38,7 @@ module.exports = function({ }) {
## inflight.Derived-1.js

```js
"use strict";
module.exports = function({ $Base }) {
class Derived extends $Base {
constructor({ $this_f }) {
Expand All @@ -54,6 +56,7 @@ module.exports = function({ $Base }) {
## preflight.js

```js
"use strict";
const $stdlib = require('@winglang/sdk');
const $plugins = ((s) => !s ? [] : s.split(';'))(process.env.WING_PLUGIN_PATHS);
const $outdir = process.env.WING_SYNTH_DIR ?? ".";
Expand Down
2 changes: 2 additions & 0 deletions libs/wingc/src/jsify/snapshots/builtins.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ source: libs/wingc/src/jsify/tests.rs
## inflight.$Closure1-1.js

```js
"use strict";
module.exports = function({ }) {
class $Closure1 {
constructor({ }) {
Expand All @@ -32,6 +33,7 @@ module.exports = function({ }) {
## preflight.js

```js
"use strict";
const $stdlib = require('@winglang/sdk');
const $plugins = ((s) => !s ? [] : s.split(';'))(process.env.WING_PLUGIN_PATHS);
const $outdir = process.env.WING_SYNTH_DIR ?? ".";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ source: libs/wingc/src/jsify/tests.rs
## inflight.A-1.js

```js
"use strict";
module.exports = function({ }) {
class A {
constructor({ }) {
Expand All @@ -35,6 +36,7 @@ module.exports = function({ }) {
## inflight.B-1.js

```js
"use strict";
module.exports = function({ $A }) {
class B {
static async bar() {
Expand All @@ -48,6 +50,7 @@ module.exports = function({ $A }) {
## preflight.js

```js
"use strict";
const $stdlib = require('@winglang/sdk');
const $plugins = ((s) => !s ? [] : s.split(';'))(process.env.WING_PLUGIN_PATHS);
const $outdir = process.env.WING_SYNTH_DIR ?? ".";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ source: libs/wingc/src/jsify/tests.rs
## inflight.$Closure1-1.js

```js
"use strict";
module.exports = function({ $b }) {
class $Closure1 {
constructor({ }) {
Expand All @@ -37,6 +38,7 @@ module.exports = function({ $b }) {
## preflight.js

```js
"use strict";
const $stdlib = require('@winglang/sdk');
const $plugins = ((s) => !s ? [] : s.split(';'))(process.env.WING_PLUGIN_PATHS);
const $outdir = process.env.WING_SYNTH_DIR ?? ".";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ source: libs/wingc/src/jsify/tests.rs
## inflight.$Closure1-1.js

```js
"use strict";
module.exports = function({ $foo }) {
class $Closure1 {
constructor({ }) {
Expand All @@ -38,6 +39,7 @@ module.exports = function({ $foo }) {
## preflight.js

```js
"use strict";
const $stdlib = require('@winglang/sdk');
const $plugins = ((s) => !s ? [] : s.split(';'))(process.env.WING_PLUGIN_PATHS);
const $outdir = process.env.WING_SYNTH_DIR ?? ".";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ source: libs/wingc/src/jsify/tests.rs
## inflight.$Closure1-1.js

```js
"use strict";
module.exports = function({ }) {
class $Closure1 {
constructor({ }) {
Expand All @@ -32,6 +33,7 @@ module.exports = function({ }) {
## inflight.$Closure2-1.js

```js
"use strict";
module.exports = function({ $foo }) {
class $Closure2 {
constructor({ }) {
Expand All @@ -50,6 +52,7 @@ module.exports = function({ $foo }) {
## preflight.js

```js
"use strict";
const $stdlib = require('@winglang/sdk');
const $plugins = ((s) => !s ? [] : s.split(';'))(process.env.WING_PLUGIN_PATHS);
const $outdir = process.env.WING_SYNTH_DIR ?? ".";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ source: libs/wingc/src/jsify/tests.rs
## inflight.$Closure1-1.js

```js
"use strict";
module.exports = function({ $x }) {
class $Closure1 {
constructor({ }) {
Expand All @@ -33,6 +34,7 @@ module.exports = function({ $x }) {
## preflight.js

```js
"use strict";
const $stdlib = require('@winglang/sdk');
const $plugins = ((s) => !s ? [] : s.split(';'))(process.env.WING_PLUGIN_PATHS);
const $outdir = process.env.WING_SYNTH_DIR ?? ".";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ source: libs/wingc/src/jsify/tests.rs
## inflight.$Closure1-1.js

```js
"use strict";
module.exports = function({ $f }) {
class $Closure1 {
constructor({ }) {
Expand All @@ -37,6 +38,7 @@ module.exports = function({ $f }) {
## inflight.Foo-1.js

```js
"use strict";
module.exports = function({ }) {
class Foo {
constructor({ }) {
Expand All @@ -51,6 +53,7 @@ module.exports = function({ }) {
## preflight.js

```js
"use strict";
const $stdlib = require('@winglang/sdk');
const $plugins = ((s) => !s ? [] : s.split(';'))(process.env.WING_PLUGIN_PATHS);
const $outdir = process.env.WING_SYNTH_DIR ?? ".";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ source: libs/wingc/src/jsify/tests.rs
## inflight.$Closure1-1.js

```js
"use strict";
module.exports = function({ $f_b }) {
class $Closure1 {
constructor({ }) {
Expand All @@ -42,6 +43,7 @@ module.exports = function({ $f_b }) {
## inflight.Foo-1.js

```js
"use strict";
module.exports = function({ }) {
class Foo {
constructor({ }) {
Expand All @@ -54,6 +56,7 @@ module.exports = function({ }) {
## preflight.js

```js
"use strict";
const $stdlib = require('@winglang/sdk');
const $plugins = ((s) => !s ? [] : s.split(';'))(process.env.WING_PLUGIN_PATHS);
const $outdir = process.env.WING_SYNTH_DIR ?? ".";
Expand Down
Loading

0 comments on commit 6209397

Please sign in to comment.