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

Update @babel/parser #75

Closed
David-Else opened this issue Jan 31, 2020 · 8 comments · Fixed by #90
Closed

Update @babel/parser #75

David-Else opened this issue Jan 31, 2020 · 8 comments · Fixed by #90
Labels
✨ Feature New refactoring or feature

Comments

@David-Else
Copy link

Deno has top level await enabled, and so does TypeScript 3.8.

At the moment any code with this in stops abracadabra working. I think it could be cured by updating https://www.npmjs.com/package/@babel/parser to the latest, it seems it supports top level await now, but I don't know if you need to enable it? I have not used Babel. Cheers!

@David-Else David-Else added the ✨ Feature New refactoring or feature label Jan 31, 2020
@nicoespeon
Copy link
Owner

@David-Else thanks for being on top of the latest features and letting us know, that really helps 👍

Yes, I guess upgrading the dependency should do the work. Maybe there's a new plugin to use here:

plugins: [
"asyncGenerators",
"bigInt",
"classPrivateMethods",
"classPrivateProperties",
"classProperties",
"decorators-legacy",
"doExpressions",
"dynamicImport",
"exportDefaultFrom",
"exportNamespaceFrom",
"functionBind",
"functionSent",
"importMeta",
"nullishCoalescingOperator",
"numericSeparator",
"objectRestSpread",
"optionalCatchBinding",
"optionalChaining",
["pipelineOperator", { proposal: "minimal" }],
"throwExpressions",
"jsx",
"typescript"
]

Hopefully, any regression should be caught by our unit tests, so it's a safe move to make.

Can you take care of it? Otherwise, @fabien0102 and I will likely do it next week 😉

@David-Else
Copy link
Author

David-Else commented Jan 31, 2020

This article goes deep on what needs to be done:

https://www.infoq.com/news/2020/01/babel-typescript-await/

I spent a while reading about how Babel works, and it seems I would need a few days to really get a grip on things. Would be cool is fabian sorted it :)

In my reading I found https://github.com/alangpierce/sucrase which is 20x faster than babel and a drop in replacement. VS Code runs a fixed version of V8/Electron for long periods of time, so abracadabra should not need all the extra babel baggage?

I don't quite know how babel stays updated with the latest typescript features, but 3.8 has import type coming too https://www.infoworld.com/article/3513938/typescript-38-unveils-new-syntax-for-type-only-imports.html

@David-Else
Copy link
Author

David-Else commented Feb 7, 2020

Just as an update, VS Code 1.42 came out yesterday. It has support built in for TS 3.8 new features for JS and TS, but ships with TS 3.7.5. To use the new feature (inc top level await and JS private properties) you need to either:

npm install -g typescript@rc

settings.json (main global file, link will be different depending on your package manager)

"typescript.tsdk": "/home/user/.nvm/versions/node/v12.15.0/pnpm-global/3/node_modules/typescript/lib"
  • or just install typescript@rc in your project and select to use it in the VS Code interface bottom right.

@David-Else
Copy link
Author

I had a go at updating babel to the latest, so this was the only change I made:

    "@babel/parser": "^7.8.4",
    "@babel/traverse": "^7.8.4",
    "@babel/types": "^7.8.3",

On running the tests I get many failure which all relate to this function in convert-to-template-literal.ts

function createTemplateLiteral(template: Template): t.TemplateLiteral {
  return t.templateLiteral(
    // Intermediate interpolated quasis shouldn't be part of the final template.
    template.quasis.filter(quasi => !isInterpolated(quasi) || quasi.tail),
    template.expressions
  );
}

Here is the first error of many, I am afraid I don't know how to fix this problem.

 FAIL  src/refactorings/convert-to-template-literal/convert-to-template-literal.test.ts
  ● Convert To Template Literal › should convert to template literal › concatenation with number, cursor on string

    TypeError: Property value of TemplateElement expected to have the following:
    Property raw expected type of string but got number
    Property cooked expected type of string but got number

      61 |  */
      62 | function templateElement(value: string | number | boolean): t.TemplateElement {
    > 63 |   return t.templateElement({
         |            ^
      64 |     raw: value,
      65 |     cooked: value
      66 |   });

      at Object.validate (node_modules/.pnpm/registry.npmjs.org/@babel/types/7.8.3/node_modules/@babel/types/lib/definitions/utils.js:185:13)
      at validateField (node_modules/.pnpm/registry.npmjs.org/@babel/types/7.8.3/node_modules/@babel/types/lib/validators/validate.js:24:9)
      at validate (node_modules/.pnpm/registry.npmjs.org/@babel/types/7.8.3/node_modules/@babel/types/lib/validators/validate.js:17:3)
      at builder (node_modules/.pnpm/registry.npmjs.org/@babel/types/7.8.3/node_modules/@babel/types/lib/builders/builder.js:38:27)
      at Object.TemplateElement (node_modules/.pnpm/registry.npmjs.org/@babel/types/7.8.3/node_modules/@babel/types/lib/builders/generated/index.js:538:31)
      at Object.templateElement (src/ast/domain.ts:63:12)
      at PrimitiveTemplate.get quasis [as quasis] (src/refactorings/convert-to-template-literal/convert-to-template-literal.ts:186:15)
      at CompositeTemplate.get quasis [as quasis] (src/refactorings/convert-to-template-literal/convert-to-template-literal.ts:135:48)
      at createTemplateLiteral (src/refactorings/convert-to-template-literal/convert-to-template-literal.ts:113:14)
      at BinaryExpression (src/refactorings/convert-to-template-literal/convert-to-template-literal.ts:64:24)

@nicoespeon
Copy link
Owner

The signature of templateElement() probably changed. We'll need to double check the changelog to see if the differences are documented =)

@David-Else
Copy link
Author

VS Code with TypeScript 3.8 built in is out tomorrow... No pressure :) abracadabra is currently not working with any new TypeScript language features, TS 3.8 has been out a couple of weeks now:

https://devblogs.microsoft.com/typescript/announcing-typescript-3-8/

@David-Else thanks for being on top of the latest features and letting us know, that really helps +1

As well as full support for top level await/private fields there is now a built in convert-to-template-string-refactoring refactoring, so maybe the abracadabra one is not needed now?

https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_43.md#convert-to-template-string-refactoring.

I won't keep hassling you I promise, this will be the last reminder. I don't think the next TS 3.9 will have any new language features, you should not have to deal with any out-dating for quite a long time :)

@nicoespeon
Copy link
Owner

nicoespeon commented Mar 6, 2020

That's fair. It's an important issue to tackle if we want to keep the extension useful.

Fabien and I weren't available to work on this in the last few weeks for personal reasons (+ conferences on my side). I'm still busy next week but we might find some time to tackle this next Thursday!

Otherwise we will tackle it in 2 weeks. Not ideal, but it will do.

From what you said, we should upgrade the version and fix the compiler errors that happens (because some function we use have changed their signatures, hopefully just a few of them).

@nicoespeon
Copy link
Owner

Released in version 3.2.2.

Thank you @David-Else 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ Feature New refactoring or feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants