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

fix(babel): loose option for babel class-properties and private-methods #9232

Merged
merged 1 commit into from May 3, 2021

Conversation

clarkdo
Copy link
Member

@clarkdo clarkdo commented May 3, 2021

Types of changes

  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

Fix #9224

@babel/plugin-proposal-class-properties can be removed now as it has been included in @babel/preset-env

image

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly. (PR: #)
  • I have added tests to cover my changes (if not applicable, please state why)
  • All new and existing tests are passing.

danielroe
danielroe previously approved these changes May 3, 2021
@pi0
Copy link
Member

pi0 commented May 3, 2021

Trying this in examples/hello-world:

<script>
class TestClass {
  // Property initializer syntax
  instanceProperty = 'test';
  boundFunction = () => {
    return this.instanceProperty
  };

  // Static class properties
  static staticProperty = 'babelIsCool';
  static staticFunction = function () {
    return TestClass.staticProperty
  };
}
console.log(new TestClass().instanceProperty )

export default {
  head: {
    title: 'Home page'
  }
}
</script>

Throws a build error (only for server):

ERROR in ..../index.vue?vue&type=script&lang=js& (.../babel-loader/lib??ref--2-0!...index?vue&type=script&lang=js&) 12:19
Module parse failed: Unexpected token (12:19)
File was processed with these loaders:
 * ./node_modules/babel-loader/lib/index.js
 * ./node_modules/vue-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| class TestClass {
|   // Property initializer syntax
>   instanceProperty = 'bork';
|   boundFunction = () => {
|     return this.instanceProperty;
 @ ./examples/hello-world/pages/index.vue?vue&type=script&lang=js& 1:0-181 1:197-200 1:202-380 1:202-380

@clarkdo
Copy link
Member Author

clarkdo commented May 3, 2021

What’s your node version?

@pi0
Copy link
Member

pi0 commented May 3, 2021

@clarkdo v14.16.1 (issues is webpack4 parser). Having plugin with loose (: false) seems not adding dependency to nuxt build (#6435)

@clarkdo
Copy link
Member Author

clarkdo commented May 3, 2021

I don't think it's a depepdency issue, I think it because your node verison supports class property, so babel won't transpile it, but webpack (old acorn) doesn't support it, I'll have a look

@clarkdo
Copy link
Member Author

clarkdo commented May 3, 2021

@pi0 Updated, can you please double check and give me a review ?

@clarkdo clarkdo unassigned pi0 May 3, 2021
@clarkdo clarkdo requested a review from pi0 May 3, 2021 12:00
@pi0 pi0 merged commit 0b35ce5 into dev May 3, 2021
@pi0 pi0 deleted the fix/babel-loose-warn branch May 3, 2021 12:06
@clarkdo
Copy link
Member Author

clarkdo commented May 3, 2021

Oops, pr title is not updated. I’ll try to amend it

@clarkdo clarkdo changed the title fix(babel): remove preset-env included plugin class-properties fix(babel): loose option for babel class-properties and private-methods May 3, 2021
pi0 pushed a commit that referenced this pull request May 8, 2021
@pi0 pi0 mentioned this pull request May 8, 2021
enwin pushed a commit to enwin/nuxt.js that referenced this pull request May 10, 2021
@hardydex
Copy link

hardydex commented Aug 6, 2021

@danielroe danielroe added the 2.x label Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Babel "loose" option error spamming in console on fresh project
4 participants