Skip to content

Syntax errors caused by JS file #18306

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
Aqours opened this issue Sep 7, 2017 · 10 comments · Fixed by #18417
Closed

Syntax errors caused by JS file #18306

Aqours opened this issue Sep 7, 2017 · 10 comments · Fixed by #18417
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@Aqours
Copy link

Aqours commented Sep 7, 2017

TypeScript Version: 2.5.2

qq 2

** example code **

Sorry, I cannot provide more code

// a.min.js file
... // compress code
export default n;

// b.js file
import * as N from './a.min';
...
export default {
  // ...
};

// c.ts file
import Re from './b';
...

tsconfig.json

{
  "compilerOptions": {
    "allowJs": true,
    "sourceMap": true,
    "declaration": false,
    "skipLibCheck": true,
    "noImplicitAny": false,
    "strictNullChecks": false,
    "module": "es2015",
    "moduleResolution": "node",
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "dom",
      "es5",
      "scripthost",
      "es2015"
    ]
  },
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}

There 34 Syntax errors caused by JS file when compile TS file(use tsc command) without module bundler. Actually, those errors should not be hinted by TS.

@Aqours
Copy link
Author

Aqours commented Sep 7, 2017

Those errors would be disappeared if I refomat code compressed in a.min.js.

@mhegazy
Copy link
Contributor

mhegazy commented Sep 7, 2017

your tsconfig.json has "allowJs": true, and i am guessing you have an import to a.min, and does not seem to be a.min.d.ts or a.min.ts available.

so either 1. do not use allowJs, 2. create a new file for a.min.d.ts

@mhegazy
Copy link
Contributor

mhegazy commented Sep 7, 2017

Also can you share the section of the .js file that is causing the errrors? looks like we have a parser error we need to fix.

@mhegazy mhegazy added the Working as Intended The behavior described is the intended behavior; this is not a bug label Sep 7, 2017
@Aqours
Copy link
Author

Aqours commented Sep 8, 2017

@mhegazy https://github.com/Aqours/Sample-Issues/tree/typescript/18306 I create a min repo which can reproduce this issue,

@mhegazy mhegazy added Bug A bug in TypeScript and removed Working as Intended The behavior described is the intended behavior; this is not a bug labels Sep 8, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Sep 8, 2017

@sandersn looks like another lambda/ternary parsing issue.

@mhegazy mhegazy added this to the TypeScript 2.6 milestone Sep 8, 2017
@sandersn
Copy link
Member

Still repros on master/2.5.3. I'll take a look.

@sandersn
Copy link
Member

#18294 fixes this. Interestingly, this is not a dupe of #18158. Bisecting tracked down d796bf1 as the buggy commit, a couple of weeks after the commits that caused #18158.

@Aqours did you try this code on older versions of Typescript to see if it also fails? I am very suspicious that two people hit 3-year-old bugs within two weeks right after I made parsing changes in the last version.

@sandersn
Copy link
Member

Here's a small repro that I believe still has the essential parse failure:

{L:function(a){ return true ? (a/8) : true },ka:function(
 ){},
};

@Aqours
Copy link
Author

Aqours commented Sep 12, 2017

@sandersn
version tested:

  • 2.4.2 failed
  • 2.3.4 failed
  • 2.1.6 failed
  • 1.8.10 failed

@sandersn
Copy link
Member

sandersn commented Sep 12, 2017

#18417 is a better fix than #18294 that works by requiring speculatively parsed arrow functions to have an = for their parameter's initalisers. Currently (x y) { } is parsed as if the user intended to write (x = y) => { }. This is true sometimes, but often it is not, especially when we parse y incorrectly, as is the case with this bug. (Reminder: here y = /8) : true },ka:function()

@sandersn sandersn added the Fixed A PR has been merged for this issue label Sep 12, 2017
@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
3 participants