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

Bug - Problem when using typescript ESNext + babel and nullish coalescing operator when assigning a property from this with a default value #2473

Closed
fdeslandes-wk opened this issue Jul 7, 2020 · 1 comment
Labels

Comments

@fdeslandes-wk
Copy link

Issue description or question

When using typescript configured with ESNext and babel as a preprocessor, the nullish coalescing operator causes problems when used to assign a value from the current object to an object property.

ex:
const obj = { a: 'test', get b() { return { val: this.a ?? 'other', } } };

This was working with the previous Wallaby version.

You can test with the following minimal-ish example from a previous bug report, which I extended with the new case:
wallaby-typescript-babel.zip

You will get this error:
[Error] Postprocessor run failure: Failed to run preprocessors on src/file.js, SyntaxError: unknown: Unexpected keyword 'this' (12:60) 
[Error]  
[Error] 10 | get b() { 
[Error] 11 | var $$c = $$wf(1); 
[Error] > 12 | return $$w(1, 13, $$c), { val: $$w(1, 14, $$c), this.a ?? $$w(1, 15, $$c), 'test' }; 
[Error] | ^ 
[Error] 13 | } 
[Error] 14 | }); 
[Error] 15 | $_$wpe(1); 
[Error] at Parser.raise (.\node_modules@babel\parser\lib\index.js:7012:17) 
[Error] at Parser.checkReservedWord (.\node_modules@babel\parser\lib\index.js:10397:12) 
[Error] at Parser.parseObjectProperty (.\node_modules@babel\parser\lib\index.js:10118:12) 
[Error] at Parser.parseObjPropValue (.\node_modules@babel\parser\lib\index.js:10138:101) 
[Error] at Parser.parseObjectMember (.\node_modules@babel\parser\lib\index.js:10062:10) 
[Error] at Parser.parseObj (.\node_modules@babel\parser\lib\index.js:9982:25) 
[Error] at Parser.parseExprAtom (.\node_modules@babel\parser\lib\index.js:9604:28) 
[Error] at Parser.parseExprSubscripts (.\node_modules@babel\parser\lib\index.js:9237:23) 
[Error] at Parser.parseMaybeUnary (.\node_modules@babel\parser\lib\index.js:9217:21) 
[Error] at Parser.parseExprOps (.\node_modules@babel\parser\lib\index.js:9083:23) 
[Error] at Parser.parseMaybeConditional (.\node_modules@babel\parser\lib\index.js:9056:23) 
[Error] at Parser.parseMaybeAssign (.\node_modules@babel\parser\lib\index.js:9015:21) 
[Error] at Parser.parseExpression (.\node_modules@babel\parser\lib\index.js:8972:36) 
[Error] at Parser.parseReturnStatement (.\node_modules@babel\parser\lib\index.js:11059:28) 
[Error] at Parser.parseStatementContent (.\node_modules@babel\parser\lib\index.js:10738:21) 
[Error] at Parser.parseStatement (.\node_modules@babel\parser\lib\index.js:10690:17) 
[Error] at Parser.parseBlockOrModuleBlockBody (.\node_modules@babel\parser\lib\index.js:11266:25) 
[Error] at Parser.parseBlockBody (.\node_modules@babel\parser\lib\index.js:11253:10) 
[Error] at Parser.parseBlock (.\node_modules@babel\parser\lib\index.js:11237:10) 
[Error] at Parser.parseFunctionBody (.\node_modules@babel\parser\lib\index.js:10256:24) 
[Error] at Parser.parseFunctionBodyAndFinish (.\node_modules@babel\parser\lib\index.js:10226:10) 
[Error] at Parser.parseMethod (.\node_modules@babel\parser\lib\index.js:10180:10) 
[Error] at Parser.parseObjectMethod (.\node_modules@babel\parser\lib\index.js:10103:12) 
[Error] at Parser.parseObjPropValue (.\node_modules@babel\parser\lib\index.js:10138:23) 
[Error] at Parser.parseObjectMember (.\node_modules@babel\parser\lib\index.js:10062:10) 
[Error] at Parser.parseObj (.\node_modules@babel\parser\lib\index.js:9982:25) 
[Error] at Parser.parseExprAtom (.\node_modules@babel\parser\lib\index.js:9604:28) 
[Error] at Parser.parseExprSubscripts (.\node_modules@babel\parser\lib\index.js:9237:23) 
[Error] at Parser.parseMaybeUnary (.\node_modules@babel\parser\lib\index.js:9217:21) 
[Error] at Parser.parseExprOps (.\node_modules@babel\parser\lib\index.js:9083:23) 
[Error] at Parser.parseMaybeConditional (.\node_modules@babel\parser\lib\index.js:9056:23) 
[Error] at Parser.parseMaybeAssign (.\node_modules@babel\parser\lib\index.js:9015:21) 
[Error] at Parser.parseParenAndDistinguishExpression (.\node_modules@babel\parser\lib\index.js:9799:28) 
[Error] at Parser.parseExprAtom (.\node_modules@babel\parser\lib\index.js:9582:21) 
[Error] at Parser.parseExprSubscripts (.\node_modules@babel\parser\lib\index.js:9237:23) 
[Error] at Parser.parseMaybeUnary (.\node_modules@babel\parser\lib\index.js:9217:21) 
[Error] at Parser.parseExprOps (.\node_modules@babel\parser\lib\index.js:9083:23) 
[Error] at Parser.parseMaybeConditional (.\node_modules@babel\parser\lib\index.js:9056:23) 
[Error] at Parser.parseMaybeAssign (.\node_modules@babel\parser\lib\index.js:9015:21) 
[Error] at Parser.parseVar (.\node_modules@babel\parser\lib\index.js:11341:26) 
[Error] at Parser.parseVarStatement (.\node_modules@babel\parser\lib\index.js:11160:10) 
[Error] at Parser.parseStatementContent (.\node_modules@babel\parser\lib\index.js:10757:21) 
[Error] at Parser.parseStatement (.\node_modules@babel\parser\lib\index.js:10690:17) 
[Error] at Parser.parseBlockOrModuleBlockBody (.\node_modules@babel\parser\lib\index.js:11266:25) 
[Error] at Parser.parseBlockBody (.\node_modules@babel\parser\lib\index.js:11253:10) 
[Error] at Parser.parseTopLevel (.\node_modules@babel\parser\lib\index.js:10621:10) 
[Error] at Parser.parse (.\node_modules@babel\parser\lib\index.js:12131:10) 
[Error] at parse (.\node_modules@babel\parser\lib\index.js:12182:38) 
[Error] at parser (.\node_modules@babel\core\lib\transformation\normalize-file.js:187:34) 
[Error] at normalizeFile (.\node_modules@babel\core\lib\transformation\normalize-file.js:113:11) 
[Error] at runSync (.\node_modules@babel\core\lib\transformation\index.js:44:43) 
[Error] at transformSync (.\node_modules@babel\core\lib\transform.js:43:38) 
[Error] at Object.transform (.\node_modules@babel\core\lib\transform.js:22:38) 
[Error] at src/**/*.js (.\wallaby.js:45:36) 
[Error] at process._tickCallback (internal/process/next_tick.js:61:11) 

Wallaby diagnostics report

{ editorVersion: '1.46.1',
  pluginVersion: '1.0.215',
  editorType: 'VSCode',
  osVersion: 'win32 10.0.18363',
  nodeVersion: 'v10.19.0',
  coreVersion: '1.0.922',
  config:
   { files: [ { pattern: 'src/**/*.ts', ignore: false, trigger: true, load: true, instrument: true, order: 1 } ],
     filesWithNoCoverageCalculated: [ 'node_modules/**/*' ],
     tests: [ { pattern: 'src/**/*spec.ts', ignore: false, trigger: true, load: true, test: true, order: 2 } ],
     testFramework: { version: 'mocha@3.2.0', configurator: 'mocha@2.0.1', reporter: 'mocha@2.0.1', starter: 'mocha@2.0.1' },
     compilers: { '**/*.?(lit)coffee?(.md)': [Function] },
     preprocessors: { 'src/**/*.js': [Function: src/**/*.js] },
     debug: true,
     workers: { initial: 1, regular: 1, recycle: false },
     hints:
      { ignoreCoverage: '__REGEXP /ignore coverage/',
        ignoreCoverageForFile: '__REGEXP /ignore file coverage/',
        commentAutoLog: '?',
        testFileSelection: { include: '__REGEXP /file\\.only/', exclude: '__REGEXP /file\\.skip/' } },
     env: { kind: 'chrome', type: 'browser', params: {}, viewportSize: { width: 800, height: 600 }, options: { width: 800, height: 600 }, bundle: true },
     diagnostics: {},
     runAllTestsInAffectedTestFile: false,
     updateNoMoreThanOneSnapshotPerTestFileRun: false,
     maxConsoleMessagesPerTest: 100,
     autoConsoleLog: true,
     delays: { run: 0, edit: 100, update: 0 },
     teardown: undefined,
     automaticTestFileSelection: true,
     runSelectedTestsOnly: false,
     extensions: {},
     reportUnhandledPromises: false,
     throwOnBeforeUnload: true,
     slowTestThreshold: 75,
     lowCoverageThreshold: 80,
     loose: undefined,
     configCode:
      'const babel = require(\'@babel/core\');\r\n\r\nmodule.exports = (w) => {\r\n  const babelCfg = {\r\n    sourceMap: true,\r\n    presets: [\r\n      [\'@babel/preset-env\', {\r\n        targets: {\r\n          browsers: [\'last 1 Chrome versions\'],\r\n        },\r\n        forceAllTransforms: true,\r\n        // Allow the use of native async await despite forceAllTransforms\r\n        exclude: [\'transform-regenerator\', \'transform-async-to-generator\'],\r\n      }],\r\n    ],\r\n    plugins: [\r\n      \'@babel/plugin-proposal-nullish-coalescing-operator\',\r\n      \'@babel/plugin-proposal-optional-chaining\',\r\n      \'@babel/plugin-proposal-object-rest-spread\',\r\n    ],\r\n  };\r\n\r\n\r\n  return {\r\n    files: [\r\n      \'src/**/*.ts\',\r\n    ],\r\n\r\n    filesWithNoCoverageCalculated: [\r\n      \'node_modules/**/*\',\r\n    ],\r\n\r\n    tests: [\r\n      \'src/**/*spec.ts\',\r\n    ],\r\n\r\n    testFramework: \'mocha\',\r\n\r\n    compilers: {\r\n      \'src/**/*.ts\': w.compilers.typeScript({ orderFilesByReferenceComments: true, noImplicitAny: false }),\r\n    },\r\n\r\n    preprocessors: {\r\n      /* Pre-processor is to late, since wallaby fails in instrumentalization phase*/\r\n      \'src/**/*.js\': file => babel.transform(file.content, babelCfg),\r\n    },\r\n    debug: true,\r\n    workers: {\r\n      initial: 1,\r\n      regular: 1,\r\n    },\r\n\r\n    hints: {\r\n      ignoreCoverage: /ignore coverage/,\r\n    },\r\n\r\n    env: {\r\n      kind: \'chrome\',\r\n    },\r\n  };\r\n};\r\n' },
  packageJSON:
   { dependencies:
      { '@babel/core': '^7.7.0',
        '@babel/plugin-proposal-nullish-coalescing-operator': '^7.7.0',
        '@babel/plugin-proposal-object-rest-spread': '^7.7.0',
        '@babel/plugin-proposal-optional-chaining': '^7.7.0',
        '@babel/polyfill': '^7.7.0',
        '@babel/preset-env': '^7.7.0',
        'babel-eslint': '~10.0.2',
        eslint: '~6.8.0',
        'eslint-config-airbnb-base': '~14.0.0',
        'eslint-plugin-import': '^2.14.0',
        tslint: '^5.18.0',
        'tslint-config-airbnb': '^5.11.1',
        typescript: '^3.7.4',
        typings: '^2.1.1' },
     devDependencies: undefined },
  fs: { numberOfFiles: 1 },
  debug:
   [ '2020-07-07T16:44:45.289Z project Wallaby Node version: v10.19.0\n',
     '2020-07-07T16:44:45.290Z project Wallaby config: F:\\fred\\Downloads\\wallaby-typescript-babel\\wallaby.js\n',
     '2020-07-07T16:44:45.922Z project File cache: C:\\Users\\frede\\.vscode\\extensions\\wallabyjs.wallaby-vscode-1.0.215\\projects\\bcd04bbc7f2799e5\n',
     '2020-07-07T16:44:45.967Z uiService Listening port 51236\n',
     '2020-07-07T16:44:45.984Z project package.json file change detected, invalidating local cache\n',
     '2020-07-07T16:44:46.020Z workers Parallelism for initial run: 1, for regular run: 1\n',
     '2020-07-07T16:44:46.020Z workers Starting run worker instance #0\n',
     '2020-07-07T16:44:46.022Z workers Web server is listening at 54911\n',
     '2020-07-07T16:44:46.035Z project File cache requires some updates, waiting required files from IDE\n',
     '2020-07-07T16:44:46.538Z workers Started run worker instance (immediate) #0\n',
     '2020-07-07T16:44:46.578Z project Stopping process pool\n',
     '2020-07-07T16:44:46.579Z project Running postprocessor\n',
     '2020-07-07T16:44:46.581Z postprocessor New TypeScript language service is required\n',
     '2020-07-07T16:44:47.287Z project Error: Failed to run preprocessors on src/file.js, SyntaxError: unknown: Unexpected keyword \'this\' (12:60)\n\n  10 |     get b() {\n  11 |         var $_$c = $_$wf(1);\n> 12 |         return $_$w(1, 13, $_$c), { val: $_$w(1, 14, $_$c), this.a ?? $_$w(1, 15, $_$c), \'test\' };\n     |                                                             ^\n  13 |     }\n  14 | });\n  15 | $_$wpe(1);\n    at Parser.raise (.\\node_modules\\@babel\\parser\\lib\\index.js:7012:17)\n    at Parser.checkReservedWord (.\\node_modules\\@babel\\parser\\lib\\index.js:10397:12)\n    at Parser.parseObjectProperty (.\\node_modules\\@babel\\parser\\lib\\index.js:10118:12)\n    at Parser.parseObjPropValue (.\\node_modules\\@babel\\parser\\lib\\index.js:10138:101)\n    at Parser.parseObjectMember (.\\node_modules\\@babel\\parser\\lib\\index.js:10062:10)\n    at Parser.parseObj (.\\node_modules\\@babel\\parser\\lib\\index.js:9982:25)\n    at Parser.parseExprAtom (.\\node_modules\\@babel\\parser\\lib\\index.js:9604:28)\n    at Parser.parseExprSubscripts (.\\node_modules\\@babel\\parser\\lib\\index.js:9237:23)\n    at Parser.parseMaybeUnary (.\\node_modules\\@babel\\parser\\lib\\index.js:9217:21)\n    at Parser.parseExprOps (.\\node_modules\\@babel\\parser\\lib\\index.js:9083:23)\n    at Parser.parseMaybeConditional (.\\node_modules\\@babel\\parser\\lib\\index.js:9056:23)\n    at Parser.parseMaybeAssign (.\\node_modules\\@babel\\parser\\lib\\index.js:9015:21)\n    at Parser.parseExpression (.\\node_modules\\@babel\\parser\\lib\\index.js:8972:36)\n    at Parser.parseReturnStatement (.\\node_modules\\@babel\\parser\\lib\\index.js:11059:28)\n    at Parser.parseStatementContent (.\\node_modules\\@babel\\parser\\lib\\index.js:10738:21)\n    at Parser.parseStatement (.\\node_modules\\@babel\\parser\\lib\\index.js:10690:17)\n    at Parser.parseBlockOrModuleBlockBody (.\\node_modules\\@babel\\parser\\lib\\index.js:11266:25)\n    at Parser.parseBlockBody (.\\node_modules\\@babel\\parser\\lib\\index.js:11253:10)\n    at Parser.parseBlock (.\\node_modules\\@babel\\parser\\lib\\index.js:11237:10)\n    at Parser.parseFunctionBody (.\\node_modules\\@babel\\parser\\lib\\index.js:10256:24)\n    at Parser.parseFunctionBodyAndFinish (.\\node_modules\\@babel\\parser\\lib\\index.js:10226:10)\n    at Parser.parseMethod (.\\node_modules\\@babel\\parser\\lib\\index.js:10180:10)\n    at Parser.parseObjectMethod (.\\node_modules\\@babel\\parser\\lib\\index.js:10103:12)\n    at Parser.parseObjPropValue (.\\node_modules\\@babel\\parser\\lib\\index.js:10138:23)\n    at Parser.parseObjectMember (.\\node_modules\\@babel\\parser\\lib\\index.js:10062:10)\n    at Parser.parseObj (.\\node_modules\\@babel\\parser\\lib\\index.js:9982:25)\n    at Parser.parseExprAtom (.\\node_modules\\@babel\\parser\\lib\\index.js:9604:28)\n    at Parser.parseExprSubscripts (.\\node_modules\\@babel\\parser\\lib\\index.js:9237:23)\n    at Parser.parseMaybeUnary (.\\node_modules\\@babel\\parser\\lib\\index.js:9217:21)\n    at Parser.parseExprOps (.\\node_modules\\@babel\\parser\\lib\\index.js:9083:23)\n    at Parser.parseMaybeConditional (.\\node_modules\\@babel\\parser\\lib\\index.js:9056:23)\n    at Parser.parseMaybeAssign (.\\node_modules\\@babel\\parser\\lib\\index.js:9015:21)\n    at Parser.parseParenAndDistinguishExpression (.\\node_modules\\@babel\\parser\\lib\\index.js:9799:28)\n    at Parser.parseExprAtom (.\\node_modules\\@babel\\parser\\lib\\index.js:9582:21)\n    at Parser.parseExprSubscripts (.\\node_modules\\@babel\\parser\\lib\\index.js:9237:23)\n    at Parser.parseMaybeUnary (.\\node_modules\\@babel\\parser\\lib\\index.js:9217:21)\n    at Parser.parseExprOps (.\\node_modules\\@babel\\parser\\lib\\index.js:9083:23)\n    at Parser.parseMaybeConditional (.\\node_modules\\@babel\\parser\\lib\\index.js:9056:23)\n    at Parser.parseMaybeAssign (.\\node_modules\\@babel\\parser\\lib\\index.js:9015:21)\n    at Parser.parseVar (.\\node_modules\\@babel\\parser\\lib\\index.js:11341:26)\n    at Parser.parseVarStatement (.\\node_modules\\@babel\\parser\\lib\\index.js:11160:10)\n    at Parser.parseStatementContent (.\\node_modules\\@babel\\parser\\lib\\index.js:10757:21)\n    at Parser.parseStatement (.\\node_modules\\@babel\\parser\\lib\\index.js:10690:17)\n    at Parser.parseBlockOrModuleBlockBody (.\\node_modules\\@babel\\parser\\lib\\index.js:11266:25)\n    at Parser.parseBlockBody (.\\node_modules\\@babel\\parser\\lib\\index.js:11253:10)\n    at Parser.parseTopLevel (.\\node_modules\\@babel\\parser\\lib\\index.js:10621:10)\n    at Parser.parse (.\\node_modules\\@babel\\parser\\lib\\index.js:12131:10)\n    at parse (.\\node_modules\\@babel\\parser\\lib\\index.js:12182:38)\n    at parser (.\\node_modules\\@babel\\core\\lib\\transformation\\normalize-file.js:187:34)\n    at normalizeFile (.\\node_modules\\@babel\\core\\lib\\transformation\\normalize-file.js:113:11)\n    at runSync (.\\node_modules\\@babel\\core\\lib\\transformation\\index.js:44:43)\n    at transformSync (.\\node_modules\\@babel\\core\\lib\\transform.js:43:38)\n    at Object.transform (.\\node_modules\\@babel\\core\\lib\\transform.js:22:38)\n    at src/**/*.js (.\\wallaby.js:45:36)\n    at process._tickCallback (internal/process/next_tick.js:61:11)\n    at c:\\Users\\frede\\.vscode\\extensions\\wallabyjs.wallaby-vscode-1.0.215\\wallaby\\server.js:24:5923\n    at process._tickCallback (internal/process/next_tick.js:68:7)\n',
     '2020-07-07T16:44:47.288Z project Test run finished\n',
     '2020-07-07T16:44:47.288Z project Test run data re-queued\n' ] }
@fdeslandes-wk fdeslandes-wk changed the title Bug - Problem when using typescript ESNext + babel and nullish coalescing operator when assigning an object property inside a getter Bug - Problem when using typescript ESNext + babel and nullish coalescing operator when assigning a property from this with a default value Jul 7, 2020
@ArtemGovorov
Copy link
Member

ArtemGovorov commented Jul 8, 2020

Thanks for submitting the bug report. The bug is fixed and the fix is published in the latest core v.1.0.923.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants