Code Monkey home page Code Monkey logo

babel-preset's People

Contributors

billyjanitsch avatar greenkeeper[bot] avatar nabeel- avatar nikita-kensho avatar slowki avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

babel-preset's Issues

Provide pragma option

This would be a convenience, forwarded as pragma to the React preset and jsxPragma to the Typescript preset, if either are enabled.

Not sure if it's justifiable as a top-level option.

Use more conservative assumptions for node_modules

Follow-up to #106.

We could use an override to be a bit stricter here, to account for third-party code using a wider range of language features than we do internally. (This will become more common over time as libraries transpile themselves less aggressively.)

We could potentially special case @kensho packages to use the regular assumptions there.

Detect Node target for library builds

We currently hardcode a target version of Node for library builds:

if (env === 'esm' || env === 'cjs') return {node: '14.14', browsers: []}

We're adding engines field to all of our projects. This corresponds to the consuming environment so the lowest satisfying version is exactly the one that we'd want as the default Node target when transpiling libraries.

We could try to detect this automatically:

  1. Starting from the file path being transpiled, traverse upwards to find a package.json.
  2. If one exists, check if it has an engines.node field.
  3. If it does, parse it and use the lowest satisfying version as the default target.
  4. Otherwise, fall back to the current explicit value as a default? Or throw, but provide an option to pass an explicit value if the auto-detection doesn't fit the use case?

Refactor test suite to use inline snapshots

The current snapshot-based is getting unwieldy:

  • Some of the fixtures are quite large and it's increasingly hard to understand what each test is verifying and what to expect from the output.
  • It runs every test through every env, even though some of the tests' output is only useful to compare across a subset of the envs.
  • Including the input code as one of the snapshots was well-intentioned, but, in practice, it's hard to parse the snapshot file well enough to directly compare input/output.
  • GitHub's diff rendering of the snapshot file often fails to correspond snapshots based on their title, so the output is a mess.

I think we should try out inline snapshots with a new test suite that is more locally-scoped. We can include a few kitchen sink tests to get the high-level integration coverage that our current suite covers as well.

Add sugar to target a specific webpack version

The forced plugin inclusion list is getting pretty long:

babel-preset/index.js

Lines 7 to 13 in e87fb8d

const APP_PLUGIN_INCLUDE_LIST = [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-private-methods',
'@babel/plugin-proposal-logical-assignment-operators',
'@babel/plugin-proposal-nullish-coalescing-operator',
'@babel/plugin-proposal-optional-chaining',
]

Most of it is only necessary for projects using webpack 4. #91 removes it entirely, but we'll likely be split between 4 and 5 for awhile.

We could add something like a webpack option to the preset to specify the version used by the consuming app. It would only affect development and production envs, modifying the forced inclusion list as needed. A simple implementation would take either 4 or 5. A more advanced implementation would take the full version, since some newer syntax is only supported in more recent versions of 5 (e.g., see the note here).

I also wonder if Babel has considered having babel-loader do this automatically. NTS to look into that.

Migrate to top-level `browserslistEnv` option

See the docs and the announcement.

Going forward, this will be the preferred way to override the browserslist env, since it integrates with plugins/presets beyond @babel/preset-env such as the new polyfill transforms.

Unfortunately, it's not a straightforward migration because the top-level option can't be specified in presets. I opened babel/babel#13317 to see whether this might change. If not, we'll need to add at least some config to each app.

Crash when Emotion's classic runtime is used in development

{emotion: true, react: {runtime: 'classic'}} in 'development' environment causes Babel to crash:

SyntaxError: /index.js: pragma and pragmaFrag cannot be set when runtime is automatic.
> 1 | import * as React from "react";
    | ^
  2 | 
  3 | export default function MyComponent() {
  4 |   return <div />;
    at File.buildCodeFrameError (/node_modules/@babel/core/lib/transformation/file/file.js:250:12)
    at NodePath.buildCodeFrameError (/node_modules/@babel/traverse/lib/path/index.js:144:21)
    at PluginPass.enter (/node_modules/@babel/helper-builder-react-jsx-experimental/lib/index.js:167:26)
    at newFn (/node_modules/@babel/traverse/lib/visitors.js:175:21)
    at NodePath._call (/node_modules/@babel/traverse/lib/path/context.js:55:20)
    at NodePath.call (/node_modules/@babel/traverse/lib/path/context.js:42:17)
    at NodePath.visit (/node_modules/@babel/traverse/lib/path/context.js:92:31)
    at TraversalContext.visitQueue (/node_modules/@babel/traverse/lib/context.js:112:16)
    at TraversalContext.visitSingle (/node_modules/@babel/traverse/lib/context.js:84:19)
    at TraversalContext.visit (/node_modules/@babel/traverse/lib/context.js:140:19) {
  code: 'BABEL_TRANSFORM_ERROR'
}

It's caused by a quirk in the way that the Emotion preset supports both runtimes simultaneously: emotion-js/emotion#2082. Not sure if the Emotion behavior will change but it can be fixed here by only setting the development option of the Emotion preset in the automatic runtime.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.