Skip to content

dynamic polyfil inclusion #24

@stefanpenner

Description

@stefanpenner

Goals:

Have babel report to us which files/modules depend on which polyfils, Babel may accomplish this by merely appending an import for the polyfil/dep the current module depends on. This would enable subsequent build-tooling to pull in only the polyfils that are needed, and isolate them to the module that explicitly depended on them.

This would help reduce the duplication caused by the small support algorithms currently inlined.

var _temporalAssertDefined = function (val, name, undef) { if (val === undef) { throw new ReferenceError(name + " is not defined - temporal dead zone"); } return true; };

var _temporalUndefined = {};

var _defineProperty = function (obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); };

Example:

given

let b = Symbol('foo')
let a = {
  [b]() {

  }
}

I would love to see something like:

import _temporalAssertDefined, { _temporalUndefined } from 'babel/temporal-assert-defined';
import _defineProperty from 'babel/defineProperty'
import Symbol from 'babel/core-js/symbol' // or something

var b = _temporalUndefined;
var a = _temporalUndefined;

b = Symbol("foo");
a = _defineProperty({}, _temporalAssertDefined(b, "b", _temporalUndefined) && b, function () {});

Todo:

  • flesh this out more.

Questions:

  • should babel report back what features the module needs?
  • should babel just drop an import and let the rest of the build system derive what is needed?
  • does each support algorithm now need to be in its own module (i think so)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions