Skip to content

Broken case statement as a result of transpiling #8461

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

Closed
niftykins opened this issue Mar 7, 2017 · 1 comment
Closed

Broken case statement as a result of transpiling #8461

niftykins opened this issue Mar 7, 2017 · 1 comment
Assignees
Milestone

Comments

@niftykins
Copy link

When transpiling the following code the result no longer breaks correctly in the 1 case which then causes the 2 case to also run.

Reproduction: https://github.com/niftykins/meteor-switch-bug (created via a meteor create and then removing some unimportant files/packages)

function test(v) {
  switch (v) {
    case 1: {
      console.log('case 1');
      const data = 5;

      // if statement seems to be required
      if (data === 123) {
        const ok = [].some(function() {
          return !!data;
        });

        // return seems to be required
        if (!ok) return 2;
      }

      break;
    }

    case 2: {
      console.log('case 2');
      break;
    }
  }
}

test(1);

The resulting code is:

function test(v) {
  switch (v) {
    case 1:
      {
        var _ret = function () {
          console.log('case 1');
          var data = 5; // if statement seems to be required

          if (data === 123) {
            var ok = [].some(function () {
              return !!data;
            }); // return seems to be required

            if (!ok) return {
                v: 2
              };
          }

          return "break";
        }();

        switch (_ret) {
          case "break":
            break;

          default:
            if ((typeof _ret === "undefined" ? "undefined" : (0, _typeof3.default)(_ret)) === "object") return _ret.v;
        }
      }

    case 2:
      {
        console.log('case 2');
        break;
      }
  }
}

Which clearly shows why the case is falling through to the next one.

This is very likely just a Babel issue, but the problem can be solved by including the es2015 preset (just adding "es2015" to the presets array in the .babelrc file in the reproduction - it's already installed) so I assume there's just something different between the presets es2015 and preset-babel-meteor which seems like it can be fixed on the meteor side.

As a note this appears to work fine in 1.5 beta 8.

Required console output for reproducing issue from reproduction:

some-dir git clone https://github.com/niftykins/meteor-switch-bug.git
Cloning into 'meteor-switch-bug'...
remote: Counting objects: 15, done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 15 (delta 0), reused 15 (delta 0), pack-reused 0
Unpacking objects: 100% (15/15), done.
Checking connectivity... done.
some-dir cd meteor-switch-bug/
meteor-switch-bug master meteor npm install
test@ /Users/nifty/Documents/some-dir/meteor-switch-bug
├─┬ babel-preset-es2015@6.22.0
│ ├── babel-plugin-check-es2015-constants@6.22.0
│ ├── babel-plugin-transform-es2015-arrow-functions@6.22.0
│ ├── babel-plugin-transform-es2015-block-scoped-functions@6.22.0
│ ├─┬ babel-plugin-transform-es2015-block-scoping@6.23.0
│ │ ├─┬ babel-template@6.23.0
│ │ │ └── babylon@6.16.1
│ │ ├─┬ babel-traverse@6.23.1
│ │ │ ├─┬ babel-code-frame@6.22.0
│ │ │ │ ├─┬ chalk@1.1.3
│ │ │ │ │ ├── ansi-styles@2.2.1
│ │ │ │ │ ├── escape-string-regexp@1.0.5
│ │ │ │ │ ├─┬ has-ansi@2.0.0
│ │ │ │ │ │ └── ansi-regex@2.1.1
│ │ │ │ │ ├── strip-ansi@3.0.1
│ │ │ │ │ └── supports-color@2.0.0
│ │ │ │ └── js-tokens@3.0.1
│ │ │ ├─┬ debug@2.6.1
│ │ │ │ └── ms@0.7.2
│ │ │ ├── globals@9.16.0
│ │ │ └─┬ invariant@2.2.2
│ │ │   └── loose-envify@1.3.1
│ │ ├─┬ babel-types@6.23.0
│ │ │ ├── esutils@2.0.2
│ │ │ └── to-fast-properties@1.0.2
│ │ └── lodash@4.17.4
│ ├─┬ babel-plugin-transform-es2015-classes@6.23.0
│ │ ├── babel-helper-define-map@6.23.0
│ │ ├── babel-helper-function-name@6.23.0
│ │ ├── babel-helper-optimise-call-expression@6.23.0
│ │ ├── babel-helper-replace-supers@6.23.0
│ │ └── babel-messages@6.23.0
│ ├── babel-plugin-transform-es2015-computed-properties@6.22.0
│ ├── babel-plugin-transform-es2015-destructuring@6.23.0
│ ├── babel-plugin-transform-es2015-duplicate-keys@6.22.0
│ ├── babel-plugin-transform-es2015-for-of@6.23.0
│ ├── babel-plugin-transform-es2015-function-name@6.22.0
│ ├── babel-plugin-transform-es2015-literals@6.22.0
│ ├── babel-plugin-transform-es2015-modules-amd@6.22.0
│ ├─┬ babel-plugin-transform-es2015-modules-commonjs@6.23.0
│ │ └── babel-plugin-transform-strict-mode@6.22.0
│ ├─┬ babel-plugin-transform-es2015-modules-systemjs@6.23.0
│ │ └── babel-helper-hoist-variables@6.22.0
│ ├── babel-plugin-transform-es2015-modules-umd@6.23.0
│ ├── babel-plugin-transform-es2015-object-super@6.22.0
│ ├─┬ babel-plugin-transform-es2015-parameters@6.23.0
│ │ ├── babel-helper-call-delegate@6.22.0
│ │ └── babel-helper-get-function-arity@6.22.0
│ ├── babel-plugin-transform-es2015-shorthand-properties@6.22.0
│ ├── babel-plugin-transform-es2015-spread@6.22.0
│ ├─┬ babel-plugin-transform-es2015-sticky-regex@6.22.0
│ │ └── babel-helper-regex@6.22.0
│ ├── babel-plugin-transform-es2015-template-literals@6.22.0
│ ├── babel-plugin-transform-es2015-typeof-symbol@6.23.0
│ ├─┬ babel-plugin-transform-es2015-unicode-regex@6.22.0
│ │ └─┬ regexpu-core@2.0.0
│ │   ├── regenerate@1.3.2
│ │   ├── regjsgen@0.2.0
│ │   └─┬ regjsparser@0.1.5
│ │     └── jsesc@0.5.0
│ └─┬ babel-plugin-transform-regenerator@6.22.0
│   └─┬ regenerator-transform@0.9.8
│     └── private@0.1.7
├─┬ babel-runtime@6.23.0
│ ├── core-js@2.4.1
│ └── regenerator-runtime@0.10.3
└─┬ meteor-node-stubs@0.2.5
  ├── asn1.js@4.9.0
  ├── assert@1.4.1
  ├── Base64@0.2.1
  ├── base64-js@1.2.0
  ├── bn.js@4.11.6
  ├── brorand@1.0.6
  ├── browserify-aes@1.0.6
  ├── browserify-cipher@1.0.0
  ├── browserify-des@1.0.0
  ├── browserify-rsa@4.0.1
  ├── browserify-sign@4.0.0
  ├── browserify-zlib@0.1.4
  ├── buffer@4.9.1
  ├── buffer-shims@1.0.0
  ├── buffer-xor@1.0.3
  ├── cipher-base@1.0.3
  ├── console-browserify@1.1.0
  ├── constants-browserify@1.0.0
  ├── core-util-is@1.0.2
  ├── create-ecdh@4.0.0
  ├── create-hash@1.1.2
  ├── create-hmac@1.1.4
  ├── crypto-browserify@3.11.0
  ├── date-now@0.1.4
  ├── des.js@1.0.0
  ├── diffie-hellman@5.0.2
  ├── domain-browser@1.1.7
  ├── elliptic@6.3.2
  ├── events@1.1.1
  ├── evp_bytestokey@1.0.0
  ├── hash.js@1.0.3
  ├── http-browserify@1.7.0
  ├── https-browserify@0.0.1
  ├── ieee754@1.1.8
  ├── indexof@0.0.1
  ├── inherits@2.0.1
  ├── isarray@1.0.0
  ├── miller-rabin@4.0.0
  ├── minimalistic-assert@1.0.0
  ├── os-browserify@0.2.1
  ├── pako@0.2.9
  ├── parse-asn1@5.0.0
  ├── path-browserify@0.0.0
  ├── pbkdf2@3.0.9
  ├── process@0.11.9
  ├── process-nextick-args@1.0.7
  ├── public-encrypt@4.0.0
  ├── punycode@1.4.1
  ├── querystring@0.2.0
  ├── querystring-es3@0.2.1
  ├── randombytes@2.0.3
  ├── readable-stream@2.2.1
  ├── ripemd160@1.0.1
  ├── sha.js@2.4.8
  ├── stream-browserify@2.0.1
  ├── string_decoder@0.10.31
  ├── timers-browserify@1.4.2
  ├── tty-browserify@0.0.0
  ├─┬ url@0.11.0
  │ └── punycode@1.3.2
  ├── util@0.10.3
  ├── util-deprecate@1.0.2
  └── vm-browserify@0.0.4

meteor-switch-bug master meteor
[[[[[ ~/Documents/some-dir/meteor-switch-bug ]]]]]

=> Started proxy.
=> Started MongoDB.
I20170307-11:45:30.006(8)? case 1
I20170307-11:45:30.200(8)? case 2
=> Started your app.

=> App running at: http://localhost:3000/
@niftykins niftykins changed the title Broke case statement as a result of transpiling Broken case statement as a result of transpiling Mar 8, 2017
@benjamn benjamn self-assigned this Mar 8, 2017
@benjamn benjamn added this to the Release 1.4.3.x milestone Mar 8, 2017
@benjamn
Copy link
Contributor

benjamn commented Mar 17, 2017

This should be fixed if you run meteor update --release 1.4.3.3-beta.4 in your application directory. Please feel free to reopen this issue if it's not resolved for you.

@benjamn benjamn closed this as completed Mar 17, 2017
@abernix abernix modified the milestones: Release 1.4.3.x, Release 1.4.3.3 Mar 21, 2017
@abernix abernix added the fixed label Mar 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants