Make sure to actually use yarn to install the main-packages, otherwise the packages.json#resolutions property will not be used and @babel/helpers would not get overruled
Overruled @babel/helpers to fix how initializers play with decorated properties. Thus circumventing the imperformant and lengthy code being generated by babel in the non-legacy option.
This commit is contained in:
parent
5ca9bec93a
commit
72f38c1137
@ -4,7 +4,7 @@
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "latest",
|
||||
"@babel/core": "^7.6.2",
|
||||
"@babel/core": "7.7.0",
|
||||
"@babel/plugin-proposal-class-properties": "latest",
|
||||
"@babel/plugin-proposal-decorators": "latest",
|
||||
"@babel/plugin-proposal-export-default-from": "latest",
|
||||
@ -37,5 +37,8 @@
|
||||
"build:csx-custom-elements": "cd ./packages/csx-custom-elements && npm run build",
|
||||
"watch:babel-transform-csx": "cd ./packages/babel-plugin-transform-csx-jsx && npm run watch",
|
||||
"watch:csx-custom-elements": "cd ./packages/csx-custom-elements && npm run watch"
|
||||
},
|
||||
"resolutions": {
|
||||
"@babel/helpers": "file:./packages/babel-helpers"
|
||||
}
|
||||
}
|
||||
|
||||
3
packages/babel-helpers/.npmignore
Normal file
3
packages/babel-helpers/.npmignore
Normal file
@ -0,0 +1,3 @@
|
||||
src
|
||||
test
|
||||
*.log
|
||||
19
packages/babel-helpers/README.md
Normal file
19
packages/babel-helpers/README.md
Normal file
@ -0,0 +1,19 @@
|
||||
# @babel/helpers
|
||||
|
||||
> Collection of helper functions used by Babel transforms.
|
||||
|
||||
See our website [@babel/helpers](https://babeljs.io/docs/en/next/babel-helpers.html) for more information.
|
||||
|
||||
## Install
|
||||
|
||||
Using npm:
|
||||
|
||||
```sh
|
||||
npm install --save-dev @babel/helpers
|
||||
```
|
||||
|
||||
or using yarn:
|
||||
|
||||
```sh
|
||||
yarn add @babel/helpers --dev
|
||||
```
|
||||
1919
packages/babel-helpers/lib/helpers.js
Normal file
1919
packages/babel-helpers/lib/helpers.js
Normal file
File diff suppressed because it is too large
Load Diff
276
packages/babel-helpers/lib/index.js
Normal file
276
packages/babel-helpers/lib/index.js
Normal file
@ -0,0 +1,276 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.get = get;
|
||||
exports.minVersion = minVersion;
|
||||
exports.getDependencies = getDependencies;
|
||||
exports.ensure = ensure;
|
||||
exports.default = exports.list = void 0;
|
||||
|
||||
var _traverse = _interopRequireDefault(require("@babel/traverse"));
|
||||
|
||||
var t = _interopRequireWildcard(require("@babel/types"));
|
||||
|
||||
var _helpers = _interopRequireDefault(require("./helpers"));
|
||||
|
||||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function makePath(path) {
|
||||
const parts = [];
|
||||
|
||||
for (; path.parentPath; path = path.parentPath) {
|
||||
parts.push(path.key);
|
||||
if (path.inList) parts.push(path.listKey);
|
||||
}
|
||||
|
||||
return parts.reverse().join(".");
|
||||
}
|
||||
|
||||
function getHelperMetadata(file) {
|
||||
const globals = new Set();
|
||||
const localBindingNames = new Set();
|
||||
const dependencies = new Map();
|
||||
let exportName;
|
||||
let exportPath;
|
||||
const exportBindingAssignments = [];
|
||||
const importPaths = [];
|
||||
const importBindingsReferences = [];
|
||||
(0, _traverse.default)(file, {
|
||||
ImportDeclaration(child) {
|
||||
const name = child.node.source.value;
|
||||
|
||||
if (!_helpers.default[name]) {
|
||||
throw child.buildCodeFrameError(`Unknown helper ${name}`);
|
||||
}
|
||||
|
||||
if (child.get("specifiers").length !== 1 || !child.get("specifiers.0").isImportDefaultSpecifier()) {
|
||||
throw child.buildCodeFrameError("Helpers can only import a default value");
|
||||
}
|
||||
|
||||
const bindingIdentifier = child.node.specifiers[0].local;
|
||||
dependencies.set(bindingIdentifier, name);
|
||||
importPaths.push(makePath(child));
|
||||
},
|
||||
|
||||
ExportDefaultDeclaration(child) {
|
||||
const decl = child.get("declaration");
|
||||
|
||||
if (decl.isFunctionDeclaration()) {
|
||||
if (!decl.node.id) {
|
||||
throw decl.buildCodeFrameError("Helpers should give names to their exported func declaration");
|
||||
}
|
||||
|
||||
exportName = decl.node.id.name;
|
||||
}
|
||||
|
||||
exportPath = makePath(child);
|
||||
},
|
||||
|
||||
ExportAllDeclaration(child) {
|
||||
throw child.buildCodeFrameError("Helpers can only export default");
|
||||
},
|
||||
|
||||
ExportNamedDeclaration(child) {
|
||||
throw child.buildCodeFrameError("Helpers can only export default");
|
||||
},
|
||||
|
||||
Statement(child) {
|
||||
if (child.isModuleDeclaration()) return;
|
||||
child.skip();
|
||||
}
|
||||
|
||||
});
|
||||
(0, _traverse.default)(file, {
|
||||
Program(path) {
|
||||
const bindings = path.scope.getAllBindings();
|
||||
Object.keys(bindings).forEach(name => {
|
||||
if (name === exportName) return;
|
||||
if (dependencies.has(bindings[name].identifier)) return;
|
||||
localBindingNames.add(name);
|
||||
});
|
||||
},
|
||||
|
||||
ReferencedIdentifier(child) {
|
||||
const name = child.node.name;
|
||||
const binding = child.scope.getBinding(name, true);
|
||||
|
||||
if (!binding) {
|
||||
globals.add(name);
|
||||
} else if (dependencies.has(binding.identifier)) {
|
||||
importBindingsReferences.push(makePath(child));
|
||||
}
|
||||
},
|
||||
|
||||
AssignmentExpression(child) {
|
||||
const left = child.get("left");
|
||||
if (!(exportName in left.getBindingIdentifiers())) return;
|
||||
|
||||
if (!left.isIdentifier()) {
|
||||
throw left.buildCodeFrameError("Only simple assignments to exports are allowed in helpers");
|
||||
}
|
||||
|
||||
const binding = child.scope.getBinding(exportName);
|
||||
|
||||
if (binding && binding.scope.path.isProgram()) {
|
||||
exportBindingAssignments.push(makePath(child));
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
if (!exportPath) throw new Error("Helpers must default-export something.");
|
||||
exportBindingAssignments.reverse();
|
||||
return {
|
||||
globals: Array.from(globals),
|
||||
localBindingNames: Array.from(localBindingNames),
|
||||
dependencies,
|
||||
exportBindingAssignments,
|
||||
exportPath,
|
||||
exportName,
|
||||
importBindingsReferences,
|
||||
importPaths
|
||||
};
|
||||
}
|
||||
|
||||
function permuteHelperAST(file, metadata, id, localBindings, getDependency) {
|
||||
if (localBindings && !id) {
|
||||
throw new Error("Unexpected local bindings for module-based helpers.");
|
||||
}
|
||||
|
||||
if (!id) return;
|
||||
const {
|
||||
localBindingNames,
|
||||
dependencies,
|
||||
exportBindingAssignments,
|
||||
exportPath,
|
||||
exportName,
|
||||
importBindingsReferences,
|
||||
importPaths
|
||||
} = metadata;
|
||||
const dependenciesRefs = {};
|
||||
dependencies.forEach((name, id) => {
|
||||
dependenciesRefs[id.name] = typeof getDependency === "function" && getDependency(name) || id;
|
||||
});
|
||||
const toRename = {};
|
||||
const bindings = new Set(localBindings || []);
|
||||
localBindingNames.forEach(name => {
|
||||
let newName = name;
|
||||
|
||||
while (bindings.has(newName)) newName = "_" + newName;
|
||||
|
||||
if (newName !== name) toRename[name] = newName;
|
||||
});
|
||||
|
||||
if (id.type === "Identifier" && exportName !== id.name) {
|
||||
toRename[exportName] = id.name;
|
||||
}
|
||||
|
||||
(0, _traverse.default)(file, {
|
||||
Program(path) {
|
||||
const exp = path.get(exportPath);
|
||||
const imps = importPaths.map(p => path.get(p));
|
||||
const impsBindingRefs = importBindingsReferences.map(p => path.get(p));
|
||||
const decl = exp.get("declaration");
|
||||
|
||||
if (id.type === "Identifier") {
|
||||
if (decl.isFunctionDeclaration()) {
|
||||
exp.replaceWith(decl);
|
||||
} else {
|
||||
exp.replaceWith(t.variableDeclaration("var", [t.variableDeclarator(id, decl.node)]));
|
||||
}
|
||||
} else if (id.type === "MemberExpression") {
|
||||
if (decl.isFunctionDeclaration()) {
|
||||
exportBindingAssignments.forEach(assignPath => {
|
||||
const assign = path.get(assignPath);
|
||||
assign.replaceWith(t.assignmentExpression("=", id, assign.node));
|
||||
});
|
||||
exp.replaceWith(decl);
|
||||
path.pushContainer("body", t.expressionStatement(t.assignmentExpression("=", id, t.identifier(exportName))));
|
||||
} else {
|
||||
exp.replaceWith(t.expressionStatement(t.assignmentExpression("=", id, decl.node)));
|
||||
}
|
||||
} else {
|
||||
throw new Error("Unexpected helper format.");
|
||||
}
|
||||
|
||||
Object.keys(toRename).forEach(name => {
|
||||
path.scope.rename(name, toRename[name]);
|
||||
});
|
||||
|
||||
for (const path of imps) path.remove();
|
||||
|
||||
for (const path of impsBindingRefs) {
|
||||
const node = t.cloneNode(dependenciesRefs[path.node.name]);
|
||||
path.replaceWith(node);
|
||||
}
|
||||
|
||||
path.stop();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
const helperData = Object.create(null);
|
||||
|
||||
function loadHelper(name) {
|
||||
if (!helperData[name]) {
|
||||
const helper = _helpers.default[name];
|
||||
|
||||
if (!helper) {
|
||||
throw Object.assign(new ReferenceError(`Unknown helper ${name}`), {
|
||||
code: "BABEL_HELPER_UNKNOWN",
|
||||
helper: name
|
||||
});
|
||||
}
|
||||
|
||||
const fn = () => {
|
||||
return t.file(helper.ast());
|
||||
};
|
||||
|
||||
const metadata = getHelperMetadata(fn());
|
||||
helperData[name] = {
|
||||
build(getDependency, id, localBindings) {
|
||||
const file = fn();
|
||||
permuteHelperAST(file, metadata, id, localBindings, getDependency);
|
||||
return {
|
||||
nodes: file.program.body,
|
||||
globals: metadata.globals
|
||||
};
|
||||
},
|
||||
|
||||
minVersion() {
|
||||
return helper.minVersion;
|
||||
},
|
||||
|
||||
dependencies: metadata.dependencies
|
||||
};
|
||||
}
|
||||
|
||||
return helperData[name];
|
||||
}
|
||||
|
||||
function get(name, getDependency, id, localBindings) {
|
||||
return loadHelper(name).build(getDependency, id, localBindings);
|
||||
}
|
||||
|
||||
function minVersion(name) {
|
||||
return loadHelper(name).minVersion();
|
||||
}
|
||||
|
||||
function getDependencies(name) {
|
||||
return Array.from(loadHelper(name).dependencies.values());
|
||||
}
|
||||
|
||||
function ensure(name) {
|
||||
loadHelper(name);
|
||||
}
|
||||
|
||||
const list = Object.keys(_helpers.default).map(name => name.replace(/^_/, "")).filter(name => name !== "__esModule");
|
||||
exports.list = list;
|
||||
var _default = get;
|
||||
exports.default = _default;
|
||||
21
packages/babel-helpers/package.json
Normal file
21
packages/babel-helpers/package.json
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "@babel/helpers",
|
||||
"version": "7.7.0",
|
||||
"description": "Collection of helper functions used by Babel transforms.",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helpers",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/template": "^7.7.0",
|
||||
"@babel/traverse": "^7.7.0",
|
||||
"@babel/types": "^7.7.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/helper-plugin-test-runner": "^7.0.0"
|
||||
}
|
||||
}
|
||||
1997
packages/babel-helpers/src/helpers.js
Normal file
1997
packages/babel-helpers/src/helpers.js
Normal file
File diff suppressed because it is too large
Load Diff
291
packages/babel-helpers/src/index.js
Normal file
291
packages/babel-helpers/src/index.js
Normal file
@ -0,0 +1,291 @@
|
||||
import traverse from "@babel/traverse";
|
||||
import * as t from "@babel/types";
|
||||
import helpers from "./helpers";
|
||||
|
||||
function makePath(path) {
|
||||
const parts = [];
|
||||
|
||||
for (; path.parentPath; path = path.parentPath) {
|
||||
parts.push(path.key);
|
||||
if (path.inList) parts.push(path.listKey);
|
||||
}
|
||||
|
||||
return parts.reverse().join(".");
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a file AST for a given helper, get a bunch of metadata about it so that Babel can quickly render
|
||||
* the helper is whatever context it is needed in.
|
||||
*/
|
||||
function getHelperMetadata(file) {
|
||||
const globals = new Set();
|
||||
const localBindingNames = new Set();
|
||||
// Maps imported identifier -> helper name
|
||||
const dependencies = new Map();
|
||||
|
||||
let exportName;
|
||||
let exportPath;
|
||||
const exportBindingAssignments = [];
|
||||
const importPaths = [];
|
||||
const importBindingsReferences = [];
|
||||
|
||||
traverse(file, {
|
||||
ImportDeclaration(child) {
|
||||
const name = child.node.source.value;
|
||||
if (!helpers[name]) {
|
||||
throw child.buildCodeFrameError(`Unknown helper ${name}`);
|
||||
}
|
||||
if (
|
||||
child.get("specifiers").length !== 1 ||
|
||||
!child.get("specifiers.0").isImportDefaultSpecifier()
|
||||
) {
|
||||
throw child.buildCodeFrameError(
|
||||
"Helpers can only import a default value",
|
||||
);
|
||||
}
|
||||
const bindingIdentifier = child.node.specifiers[0].local;
|
||||
dependencies.set(bindingIdentifier, name);
|
||||
importPaths.push(makePath(child));
|
||||
},
|
||||
ExportDefaultDeclaration(child) {
|
||||
const decl = child.get("declaration");
|
||||
|
||||
if (decl.isFunctionDeclaration()) {
|
||||
if (!decl.node.id) {
|
||||
throw decl.buildCodeFrameError(
|
||||
"Helpers should give names to their exported func declaration",
|
||||
);
|
||||
}
|
||||
|
||||
exportName = decl.node.id.name;
|
||||
}
|
||||
exportPath = makePath(child);
|
||||
},
|
||||
ExportAllDeclaration(child) {
|
||||
throw child.buildCodeFrameError("Helpers can only export default");
|
||||
},
|
||||
ExportNamedDeclaration(child) {
|
||||
throw child.buildCodeFrameError("Helpers can only export default");
|
||||
},
|
||||
Statement(child) {
|
||||
if (child.isModuleDeclaration()) return;
|
||||
|
||||
child.skip();
|
||||
},
|
||||
});
|
||||
|
||||
traverse(file, {
|
||||
Program(path) {
|
||||
const bindings = path.scope.getAllBindings();
|
||||
|
||||
Object.keys(bindings).forEach(name => {
|
||||
if (name === exportName) return;
|
||||
if (dependencies.has(bindings[name].identifier)) return;
|
||||
|
||||
localBindingNames.add(name);
|
||||
});
|
||||
},
|
||||
ReferencedIdentifier(child) {
|
||||
const name = child.node.name;
|
||||
const binding = child.scope.getBinding(name, /* noGlobal */ true);
|
||||
if (!binding) {
|
||||
globals.add(name);
|
||||
} else if (dependencies.has(binding.identifier)) {
|
||||
importBindingsReferences.push(makePath(child));
|
||||
}
|
||||
},
|
||||
AssignmentExpression(child) {
|
||||
const left = child.get("left");
|
||||
|
||||
if (!(exportName in left.getBindingIdentifiers())) return;
|
||||
|
||||
if (!left.isIdentifier()) {
|
||||
throw left.buildCodeFrameError(
|
||||
"Only simple assignments to exports are allowed in helpers",
|
||||
);
|
||||
}
|
||||
|
||||
const binding = child.scope.getBinding(exportName);
|
||||
|
||||
if (binding && binding.scope.path.isProgram()) {
|
||||
exportBindingAssignments.push(makePath(child));
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
if (!exportPath) throw new Error("Helpers must default-export something.");
|
||||
|
||||
// Process these in reverse so that mutating the references does not invalidate any later paths in
|
||||
// the list.
|
||||
exportBindingAssignments.reverse();
|
||||
|
||||
return {
|
||||
globals: Array.from(globals),
|
||||
localBindingNames: Array.from(localBindingNames),
|
||||
dependencies,
|
||||
exportBindingAssignments,
|
||||
exportPath,
|
||||
exportName,
|
||||
importBindingsReferences,
|
||||
importPaths,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a helper AST and information about how it will be used, update the AST to match the usage.
|
||||
*/
|
||||
function permuteHelperAST(file, metadata, id, localBindings, getDependency) {
|
||||
if (localBindings && !id) {
|
||||
throw new Error("Unexpected local bindings for module-based helpers.");
|
||||
}
|
||||
|
||||
if (!id) return;
|
||||
|
||||
const {
|
||||
localBindingNames,
|
||||
dependencies,
|
||||
exportBindingAssignments,
|
||||
exportPath,
|
||||
exportName,
|
||||
importBindingsReferences,
|
||||
importPaths,
|
||||
} = metadata;
|
||||
|
||||
const dependenciesRefs = {};
|
||||
dependencies.forEach((name, id) => {
|
||||
dependenciesRefs[id.name] =
|
||||
(typeof getDependency === "function" && getDependency(name)) || id;
|
||||
});
|
||||
|
||||
const toRename = {};
|
||||
const bindings = new Set(localBindings || []);
|
||||
localBindingNames.forEach(name => {
|
||||
let newName = name;
|
||||
while (bindings.has(newName)) newName = "_" + newName;
|
||||
|
||||
if (newName !== name) toRename[name] = newName;
|
||||
});
|
||||
|
||||
if (id.type === "Identifier" && exportName !== id.name) {
|
||||
toRename[exportName] = id.name;
|
||||
}
|
||||
|
||||
traverse(file, {
|
||||
Program(path) {
|
||||
// We need to compute these in advance because removing nodes would
|
||||
// invalidate the paths.
|
||||
const exp = path.get(exportPath);
|
||||
const imps = importPaths.map(p => path.get(p));
|
||||
const impsBindingRefs = importBindingsReferences.map(p => path.get(p));
|
||||
|
||||
const decl = exp.get("declaration");
|
||||
if (id.type === "Identifier") {
|
||||
if (decl.isFunctionDeclaration()) {
|
||||
exp.replaceWith(decl);
|
||||
} else {
|
||||
exp.replaceWith(
|
||||
t.variableDeclaration("var", [t.variableDeclarator(id, decl.node)]),
|
||||
);
|
||||
}
|
||||
} else if (id.type === "MemberExpression") {
|
||||
if (decl.isFunctionDeclaration()) {
|
||||
exportBindingAssignments.forEach(assignPath => {
|
||||
const assign = path.get(assignPath);
|
||||
assign.replaceWith(t.assignmentExpression("=", id, assign.node));
|
||||
});
|
||||
exp.replaceWith(decl);
|
||||
path.pushContainer(
|
||||
"body",
|
||||
t.expressionStatement(
|
||||
t.assignmentExpression("=", id, t.identifier(exportName)),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
exp.replaceWith(
|
||||
t.expressionStatement(t.assignmentExpression("=", id, decl.node)),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
throw new Error("Unexpected helper format.");
|
||||
}
|
||||
|
||||
Object.keys(toRename).forEach(name => {
|
||||
path.scope.rename(name, toRename[name]);
|
||||
});
|
||||
|
||||
for (const path of imps) path.remove();
|
||||
for (const path of impsBindingRefs) {
|
||||
const node = t.cloneNode(dependenciesRefs[path.node.name]);
|
||||
path.replaceWith(node);
|
||||
}
|
||||
|
||||
// We only use "traverse" for all the handy scoping helpers, so we can stop immediately without
|
||||
// actually doing the traversal.
|
||||
path.stop();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const helperData = Object.create(null);
|
||||
function loadHelper(name) {
|
||||
if (!helperData[name]) {
|
||||
const helper = helpers[name];
|
||||
if (!helper) {
|
||||
throw Object.assign(new ReferenceError(`Unknown helper ${name}`), {
|
||||
code: "BABEL_HELPER_UNKNOWN",
|
||||
helper: name,
|
||||
});
|
||||
}
|
||||
|
||||
const fn = () => {
|
||||
return t.file(helper.ast());
|
||||
};
|
||||
|
||||
const metadata = getHelperMetadata(fn());
|
||||
|
||||
helperData[name] = {
|
||||
build(getDependency, id, localBindings) {
|
||||
const file = fn();
|
||||
permuteHelperAST(file, metadata, id, localBindings, getDependency);
|
||||
|
||||
return {
|
||||
nodes: file.program.body,
|
||||
globals: metadata.globals,
|
||||
};
|
||||
},
|
||||
minVersion() {
|
||||
return helper.minVersion;
|
||||
},
|
||||
dependencies: metadata.dependencies,
|
||||
};
|
||||
}
|
||||
|
||||
return helperData[name];
|
||||
}
|
||||
|
||||
export function get(
|
||||
name,
|
||||
getDependency?: string => ?t.Expression,
|
||||
id?,
|
||||
localBindings?: string[],
|
||||
) {
|
||||
return loadHelper(name).build(getDependency, id, localBindings);
|
||||
}
|
||||
|
||||
export function minVersion(name: string) {
|
||||
return loadHelper(name).minVersion();
|
||||
}
|
||||
|
||||
export function getDependencies(name: string): $ReadOnlyArray<string> {
|
||||
return Array.from(loadHelper(name).dependencies.values());
|
||||
}
|
||||
|
||||
export function ensure(name: string) {
|
||||
loadHelper(name);
|
||||
}
|
||||
|
||||
export const list = Object.keys(helpers)
|
||||
.map(name => name.replace(/^_/, ""))
|
||||
.filter(name => name !== "__esModule");
|
||||
|
||||
export default get;
|
||||
1
packages/babel-helpers/test/fixtures/dependencies/basic/input.js
vendored
Normal file
1
packages/babel-helpers/test/fixtures/dependencies/basic/input.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
REPLACE_ME;
|
||||
3
packages/babel-helpers/test/fixtures/dependencies/basic/options.json
vendored
Normal file
3
packages/babel-helpers/test/fixtures/dependencies/basic/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["./plugin"]
|
||||
}
|
||||
5
packages/babel-helpers/test/fixtures/dependencies/basic/output.js
vendored
Normal file
5
packages/babel-helpers/test/fixtures/dependencies/basic/output.js
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
function _$_basic_main() { return _$_basic_dependency(); }
|
||||
|
||||
function _$_basic_dependency() {}
|
||||
|
||||
_$_basic_main;
|
||||
25
packages/babel-helpers/test/fixtures/dependencies/basic/plugin.js
vendored
Normal file
25
packages/babel-helpers/test/fixtures/dependencies/basic/plugin.js
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
const defineHelper = require("../../../helpers/define-helper").default;
|
||||
|
||||
const dependency = defineHelper(__dirname, "dependency", `
|
||||
export default function fn() {}
|
||||
`);
|
||||
|
||||
const main = defineHelper(__dirname, "main", `
|
||||
import dep from "${dependency}";
|
||||
|
||||
export default function helper() {
|
||||
return dep();
|
||||
}
|
||||
`);
|
||||
|
||||
module.exports = function() {
|
||||
return {
|
||||
visitor: {
|
||||
Identifier(path) {
|
||||
if (path.node.name !== "REPLACE_ME") return;
|
||||
const helper = this.addHelper(main);
|
||||
path.replaceWith(helper);
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
1
packages/babel-helpers/test/fixtures/dependencies/deep/input.js
vendored
Normal file
1
packages/babel-helpers/test/fixtures/dependencies/deep/input.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
REPLACE_ME;
|
||||
3
packages/babel-helpers/test/fixtures/dependencies/deep/options.json
vendored
Normal file
3
packages/babel-helpers/test/fixtures/dependencies/deep/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["./plugin"]
|
||||
}
|
||||
7
packages/babel-helpers/test/fixtures/dependencies/deep/output.js
vendored
Normal file
7
packages/babel-helpers/test/fixtures/dependencies/deep/output.js
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
function _$_deep_main() { return _$_deep_dependency(); }
|
||||
|
||||
function _$_deep_dependency() { return _$_deep_dependencyDeep; }
|
||||
|
||||
function _$_deep_dependencyDeep() {}
|
||||
|
||||
_$_deep_main;
|
||||
30
packages/babel-helpers/test/fixtures/dependencies/deep/plugin.js
vendored
Normal file
30
packages/babel-helpers/test/fixtures/dependencies/deep/plugin.js
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
const defineHelper = require("../../../helpers/define-helper").default;
|
||||
|
||||
const dependencyDeep = defineHelper(__dirname, "dependencyDeep", `
|
||||
export default function fn() {}
|
||||
`)
|
||||
|
||||
const dependency = defineHelper(__dirname, "dependency", `
|
||||
import f from "${dependencyDeep}";
|
||||
export default function fn() { return f; }
|
||||
`);
|
||||
|
||||
const main = defineHelper(__dirname, "main", `
|
||||
import dep from "${dependency}";
|
||||
|
||||
export default function helper() {
|
||||
return dep();
|
||||
}
|
||||
`);
|
||||
|
||||
module.exports = function() {
|
||||
return {
|
||||
visitor: {
|
||||
Identifier(path) {
|
||||
if (path.node.name !== "REPLACE_ME") return;
|
||||
const helper = this.addHelper(main);
|
||||
path.replaceWith(helper);
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
1
packages/babel-helpers/test/fixtures/dependencies/missing/input.js
vendored
Normal file
1
packages/babel-helpers/test/fixtures/dependencies/missing/input.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
REPLACE_ME;
|
||||
4
packages/babel-helpers/test/fixtures/dependencies/missing/options.json
vendored
Normal file
4
packages/babel-helpers/test/fixtures/dependencies/missing/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": ["./plugin"],
|
||||
"throws": " "
|
||||
}
|
||||
21
packages/babel-helpers/test/fixtures/dependencies/missing/plugin.js
vendored
Normal file
21
packages/babel-helpers/test/fixtures/dependencies/missing/plugin.js
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
const defineHelper = require("../../../helpers/define-helper").default;
|
||||
|
||||
const main = defineHelper(__dirname, "main", `
|
||||
import dep from "(!!!)%-..a,4892 missing";
|
||||
|
||||
export default function helper() {
|
||||
return dep();
|
||||
}
|
||||
`);
|
||||
|
||||
module.exports = function() {
|
||||
return {
|
||||
visitor: {
|
||||
Identifier(path) {
|
||||
if (path.node.name !== "REPLACE_ME") return;
|
||||
const helper = this.addHelper(main);
|
||||
path.replaceWith(helper);
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
1
packages/babel-helpers/test/fixtures/dependencies/multiple/input.js
vendored
Normal file
1
packages/babel-helpers/test/fixtures/dependencies/multiple/input.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
REPLACE_ME;
|
||||
3
packages/babel-helpers/test/fixtures/dependencies/multiple/options.json
vendored
Normal file
3
packages/babel-helpers/test/fixtures/dependencies/multiple/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["./plugin"]
|
||||
}
|
||||
7
packages/babel-helpers/test/fixtures/dependencies/multiple/output.js
vendored
Normal file
7
packages/babel-helpers/test/fixtures/dependencies/multiple/output.js
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
function _$_multiple_main() { return _$_multiple_dependency() + _$_multiple_dependency2(); }
|
||||
|
||||
function _$_multiple_dependency2() { 1; }
|
||||
|
||||
function _$_multiple_dependency() { 0; }
|
||||
|
||||
_$_multiple_main;
|
||||
30
packages/babel-helpers/test/fixtures/dependencies/multiple/plugin.js
vendored
Normal file
30
packages/babel-helpers/test/fixtures/dependencies/multiple/plugin.js
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
const defineHelper = require("../../../helpers/define-helper").default;
|
||||
|
||||
const dependency1 = defineHelper(__dirname, "dependency1", `
|
||||
export default function fn() { 0; }
|
||||
`);
|
||||
|
||||
const dependency2 = defineHelper(__dirname, "dependency2", `
|
||||
export default function fn() { 1; }
|
||||
`);
|
||||
|
||||
const main = defineHelper(__dirname, "main", `
|
||||
import dep1 from "${dependency1}";
|
||||
import dep2 from "${dependency2}";
|
||||
|
||||
export default function helper() {
|
||||
return dep1() + dep2();
|
||||
}
|
||||
`);
|
||||
|
||||
module.exports = function() {
|
||||
return {
|
||||
visitor: {
|
||||
Identifier(path) {
|
||||
if (path.node.name !== "REPLACE_ME") return;
|
||||
const helper = this.addHelper(main);
|
||||
path.replaceWith(helper);
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
1
packages/babel-helpers/test/fixtures/dependencies/rename-binding-equal/input.js
vendored
Normal file
1
packages/babel-helpers/test/fixtures/dependencies/rename-binding-equal/input.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
REPLACE_ME;
|
||||
3
packages/babel-helpers/test/fixtures/dependencies/rename-binding-equal/options.json
vendored
Normal file
3
packages/babel-helpers/test/fixtures/dependencies/rename-binding-equal/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["./plugin"]
|
||||
}
|
||||
9
packages/babel-helpers/test/fixtures/dependencies/rename-binding-equal/output.js
vendored
Normal file
9
packages/babel-helpers/test/fixtures/dependencies/rename-binding-equal/output.js
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
let _foo = "main";
|
||||
|
||||
function _$_renameBindingEqual_main() { return _$_renameBindingEqual_dependency() + _foo; }
|
||||
|
||||
let foo = "dependency";
|
||||
|
||||
function _$_renameBindingEqual_dependency() { return foo; }
|
||||
|
||||
_$_renameBindingEqual_main;
|
||||
28
packages/babel-helpers/test/fixtures/dependencies/rename-binding-equal/plugin.js
vendored
Normal file
28
packages/babel-helpers/test/fixtures/dependencies/rename-binding-equal/plugin.js
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
const defineHelper = require("../../../helpers/define-helper").default;
|
||||
|
||||
const dependency = defineHelper(__dirname, "dependency", `
|
||||
let foo = "dependency";
|
||||
export default function fn() { return foo }
|
||||
`);
|
||||
|
||||
const main = defineHelper(__dirname, "main", `
|
||||
import dep from "${dependency}";
|
||||
|
||||
let foo = "main";
|
||||
|
||||
export default function helper() {
|
||||
return dep() + foo;
|
||||
}
|
||||
`);
|
||||
|
||||
module.exports = function() {
|
||||
return {
|
||||
visitor: {
|
||||
Identifier(path) {
|
||||
if (path.node.name !== "REPLACE_ME") return;
|
||||
const helper = this.addHelper(main);
|
||||
path.replaceWith(helper);
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
3
packages/babel-helpers/test/fixtures/dependencies/rename-deep-global/input.js
vendored
Normal file
3
packages/babel-helpers/test/fixtures/dependencies/rename-deep-global/input.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
REPLACE_ME;
|
||||
|
||||
let Promise = "I will be a good guy!";
|
||||
3
packages/babel-helpers/test/fixtures/dependencies/rename-deep-global/options.json
vendored
Normal file
3
packages/babel-helpers/test/fixtures/dependencies/rename-deep-global/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["./plugin"]
|
||||
}
|
||||
6
packages/babel-helpers/test/fixtures/dependencies/rename-deep-global/output.js
vendored
Normal file
6
packages/babel-helpers/test/fixtures/dependencies/rename-deep-global/output.js
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
function _$_renameDeepGlobal_main() { return _$_renameDeepGlobal_dependency() || Promise; }
|
||||
|
||||
function _$_renameDeepGlobal_dependency() { return Promise; }
|
||||
|
||||
_$_renameDeepGlobal_main;
|
||||
let _Promise = "I will be a good guy!";
|
||||
27
packages/babel-helpers/test/fixtures/dependencies/rename-deep-global/plugin.js
vendored
Normal file
27
packages/babel-helpers/test/fixtures/dependencies/rename-deep-global/plugin.js
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
const defineHelper = require("../../../helpers/define-helper").default;
|
||||
|
||||
const dependency = defineHelper(__dirname, "dependency", `
|
||||
export default function fn() {
|
||||
return Promise;
|
||||
}
|
||||
`);
|
||||
|
||||
const main = defineHelper(__dirname, "main", `
|
||||
import dep from "${dependency}";
|
||||
|
||||
export default function helper() {
|
||||
return dep() || Promise;
|
||||
}
|
||||
`);
|
||||
|
||||
module.exports = function() {
|
||||
return {
|
||||
visitor: {
|
||||
Identifier(path) {
|
||||
if (path.node.name !== "REPLACE_ME") return;
|
||||
const helper = this.addHelper(main);
|
||||
path.replaceWith(helper);
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
2
packages/babel-helpers/test/fixtures/dependencies/reuse-dependency/input.js
vendored
Normal file
2
packages/babel-helpers/test/fixtures/dependencies/reuse-dependency/input.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
REPLACE_ME_1;
|
||||
REPLACE_ME_2;
|
||||
3
packages/babel-helpers/test/fixtures/dependencies/reuse-dependency/options.json
vendored
Normal file
3
packages/babel-helpers/test/fixtures/dependencies/reuse-dependency/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["./plugin"]
|
||||
}
|
||||
6
packages/babel-helpers/test/fixtures/dependencies/reuse-dependency/output.js
vendored
Normal file
6
packages/babel-helpers/test/fixtures/dependencies/reuse-dependency/output.js
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
function _$_reuseDependency_main() { return _$_reuseDependency_dependency(); }
|
||||
|
||||
function _$_reuseDependency_dependency() { 0; }
|
||||
|
||||
_$_reuseDependency_main;
|
||||
_$_reuseDependency_dependency;
|
||||
29
packages/babel-helpers/test/fixtures/dependencies/reuse-dependency/plugin.js
vendored
Normal file
29
packages/babel-helpers/test/fixtures/dependencies/reuse-dependency/plugin.js
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
const defineHelper = require("../../../helpers/define-helper").default;
|
||||
|
||||
const dependency = defineHelper(__dirname, "dependency", `
|
||||
export default function fn() { 0; }
|
||||
`);
|
||||
|
||||
const main = defineHelper(__dirname, "main", `
|
||||
import dep from "${dependency}";
|
||||
|
||||
export default function helper() {
|
||||
return dep();
|
||||
}
|
||||
`);
|
||||
|
||||
module.exports = function() {
|
||||
return {
|
||||
visitor: {
|
||||
Identifier(path) {
|
||||
if (path.node.name === "REPLACE_ME_1") {
|
||||
const mainHelper = this.addHelper(main);
|
||||
path.replaceWith(mainHelper);
|
||||
} else if (path.node.name === "REPLACE_ME_2") {
|
||||
const dependencyHelper = this.addHelper(dependency);
|
||||
path.replaceWith(dependencyHelper);
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
1
packages/babel-helpers/test/fixtures/dependencies/variable-same-name-dependency/input.js
vendored
Normal file
1
packages/babel-helpers/test/fixtures/dependencies/variable-same-name-dependency/input.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
REPLACE_ME;
|
||||
3
packages/babel-helpers/test/fixtures/dependencies/variable-same-name-dependency/options.json
vendored
Normal file
3
packages/babel-helpers/test/fixtures/dependencies/variable-same-name-dependency/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["./plugin"]
|
||||
}
|
||||
5
packages/babel-helpers/test/fixtures/dependencies/variable-same-name-dependency/output.js
vendored
Normal file
5
packages/babel-helpers/test/fixtures/dependencies/variable-same-name-dependency/output.js
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
function _$_variableSameNameDependency_main() { let x = _$_variableSameNameDependency_dependency; return function (dep) { return x() + dep; }; }
|
||||
|
||||
function _$_variableSameNameDependency_dependency() {}
|
||||
|
||||
_$_variableSameNameDependency_main;
|
||||
28
packages/babel-helpers/test/fixtures/dependencies/variable-same-name-dependency/plugin.js
vendored
Normal file
28
packages/babel-helpers/test/fixtures/dependencies/variable-same-name-dependency/plugin.js
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
const defineHelper = require("../../../helpers/define-helper").default;
|
||||
|
||||
const dependency = defineHelper(__dirname, "dependency", `
|
||||
export default function fn() {}
|
||||
`);
|
||||
|
||||
const main = defineHelper(__dirname, "main", `
|
||||
import dep from "${dependency}";
|
||||
|
||||
export default function helper() {
|
||||
let x = dep;
|
||||
return function (dep) {
|
||||
return x() + dep;
|
||||
}
|
||||
}
|
||||
`);
|
||||
|
||||
module.exports = function() {
|
||||
return {
|
||||
visitor: {
|
||||
Identifier(path) {
|
||||
if (path.node.name !== "REPLACE_ME") return;
|
||||
const helper = this.addHelper(main);
|
||||
path.replaceWith(helper);
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
26
packages/babel-helpers/test/helpers/define-helper.js
Normal file
26
packages/babel-helpers/test/helpers/define-helper.js
Normal file
@ -0,0 +1,26 @@
|
||||
import path from "path";
|
||||
import template from "@babel/template";
|
||||
import helpers from "../../lib/helpers";
|
||||
|
||||
function getHelperId(dir, name) {
|
||||
const testName = path.basename(dir);
|
||||
return `_$_${testName}_${name}`;
|
||||
}
|
||||
|
||||
export default function defineHelper(
|
||||
dir: string,
|
||||
name: string,
|
||||
code: string,
|
||||
): string {
|
||||
const id = getHelperId(dir, name);
|
||||
if (id in helpers) {
|
||||
throw new Error(`The ${id} helper is already defined.`);
|
||||
}
|
||||
Object.defineProperty(helpers, id, {
|
||||
value: {
|
||||
minVersion: "7.0.0-beta.0",
|
||||
ast: template.program(code),
|
||||
},
|
||||
});
|
||||
return id;
|
||||
}
|
||||
3
packages/babel-helpers/test/index.js
Normal file
3
packages/babel-helpers/test/index.js
Normal file
@ -0,0 +1,3 @@
|
||||
import runner from "@babel/helper-plugin-test-runner";
|
||||
|
||||
runner(__dirname);
|
||||
@ -2,7 +2,7 @@
|
||||
"presets": [
|
||||
],
|
||||
"plugins": [
|
||||
[ "@babel/plugin-proposal-decorators" , { "decoratorsBeforeExport": true }],
|
||||
[ "@babel/plugin-proposal-decorators" , { "legacy": true }],
|
||||
[ "@babel/plugin-proposal-class-properties", { "loose": true } ],
|
||||
[ "@babel/plugin-proposal-private-methods", {"loose": true } ],
|
||||
[ "@babel/plugin-proposal-optional-chaining" ],
|
||||
|
||||
@ -1,43 +1,56 @@
|
||||
import {render} from "../vdom";
|
||||
|
||||
|
||||
/** Helper class to mark an initializer-value to be used on first get of a value**/
|
||||
class InitializerValue{ constructor(value){ this.value = value; } }
|
||||
|
||||
/**
|
||||
* The decorators proposal has changed since @babel implemented it. This code will need to change at some point...
|
||||
* THIS IS TOTALLY FIGGIN BROKEN!! valueMap used to be just value, but it turns out is not unique amongst decorated props.
|
||||
* (it appears to be run once per class definition, and thus multiple instances would share the same value-reference)
|
||||
*/
|
||||
export function State() {
|
||||
return function decorator(target){
|
||||
let key = target.key;
|
||||
let descriptor = target.descriptor;
|
||||
let valueMap = new WeakMap();
|
||||
return function decorator(target, key, descriptor){
|
||||
let {get: oldGet, set: oldSet} = descriptor;
|
||||
let valueKey='__'+key;
|
||||
|
||||
// Add a getter/setter or replace if they're already there with something that intercepts it (this gets a whole lot easyer in the new proposal if i'm not mistaken)
|
||||
descriptor['get'] = oldGet || (function(){
|
||||
return valueMap.get(this)
|
||||
});
|
||||
descriptor['set'] = function(newValue){
|
||||
let oldValue = descriptor.get.call(this);
|
||||
if(newValue!==oldValue){
|
||||
valueMap.set(this,newValue);
|
||||
this.markDirty && this.markDirty();
|
||||
|
||||
// Rewrite the property as if using getters and setters (if needed)
|
||||
descriptor.get = oldGet = oldGet || function(){
|
||||
let val = this[valueKey];
|
||||
if(val instanceof InitializerValue){
|
||||
this[valueKey] = val = val.value.call(this);
|
||||
}
|
||||
if(oldSet) return oldSet.call(this, newValue);
|
||||
return val;
|
||||
};
|
||||
|
||||
// CAUTION: this is dangerous. We need intend to conver regular fields to get/set methods here.
|
||||
delete descriptor.writable;
|
||||
oldSet = oldSet || function(newVal){
|
||||
this[valueKey]=newVal;
|
||||
return newVal;
|
||||
};
|
||||
// Overwrite the setter to call markDirty whenever it is used
|
||||
descriptor.set = function(newValue){
|
||||
let result = oldSet.call(this, newValue);
|
||||
this.markDirty && this.markDirty();
|
||||
return result;
|
||||
};
|
||||
|
||||
// Update the descriptor to match with using getters and setters
|
||||
target.kind = 'method'; // update to get and set if need be..
|
||||
delete descriptor.writable;
|
||||
|
||||
// CAUTION: this is again dangerous, the initialize function should be called right before the constructor, but after it was fully defined.
|
||||
if(target.initializer){
|
||||
valueMap.set(target, target.initializer(target));
|
||||
delete target.initializer;
|
||||
// Catch usage of initial value or initalizers
|
||||
if(descriptor.value){
|
||||
Object.defineProperty(target, valueKey, {
|
||||
writable: true,
|
||||
value: descriptor.value
|
||||
});
|
||||
delete descriptor.value;
|
||||
}else if(descriptor.initializer){
|
||||
Object.defineProperty(target, valueKey, {
|
||||
writable: true,
|
||||
value: new InitializerValue(descriptor.initializer)
|
||||
});
|
||||
delete descriptor.initializer;
|
||||
}
|
||||
|
||||
return target;
|
||||
|
||||
return descriptor;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -2,21 +2,16 @@
|
||||
* The decorators proposal has changed since @babel implemented it. This code will need to change at some point...
|
||||
*/
|
||||
export function defineElement(tagName, options) {
|
||||
return function decorator(target) {
|
||||
// Queue defining element in a finisher, because apparantly thats how the non-legacy decorator proposal works (again, new proposal will be different...)
|
||||
target.finisher = (finishedTarget)=>{
|
||||
// Register the tagName as a custom-element with the browser
|
||||
window.customElements.define(tagName, finishedTarget, options);
|
||||
|
||||
// Define the chosen tagName on the class itself so our vdom.render-function knows what DOM-Element to create
|
||||
Object.defineProperty(finishedTarget, 'tagName', {
|
||||
value: tagName,
|
||||
writable: false,
|
||||
enumerable: false,
|
||||
configurable: false
|
||||
});
|
||||
return finishedTarget;
|
||||
};
|
||||
return target;
|
||||
return function decorator(targetClass) {
|
||||
Object.defineProperty(targetClass, 'tagName', {
|
||||
value: tagName,
|
||||
writable: false,
|
||||
enumerable: false,
|
||||
configurable: false
|
||||
});
|
||||
|
||||
// Register the tagName as a custom-element with the browser
|
||||
window.customElements.define(tagName, targetClass, options); // Define the chosen tagName on the class itself so our vdom.render-function knows what DOM-Element to create
|
||||
return targetClass;
|
||||
};
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
}]
|
||||
],
|
||||
"plugins": [
|
||||
[ "@babel/plugin-proposal-decorators", { "decoratorsBeforeExport": true }],
|
||||
[ "@babel/plugin-proposal-decorators", { "legacy": true }],
|
||||
[ "@babel/plugin-proposal-class-properties", { "loose": true } ],
|
||||
[ "@babel/plugin-proposal-private-methods", {"loose": true } ],
|
||||
[ "@babel/plugin-proposal-optional-chaining" ],
|
||||
|
||||
@ -7,20 +7,10 @@ import {TodoItem} from './todo-item';
|
||||
@defineElement('my-todo')
|
||||
export class MyTodo extends CustomElement{
|
||||
uid = 1;
|
||||
@State() todos;
|
||||
// = [
|
||||
// {id: this.uid++, text: "my initial todo", checked: false },
|
||||
// {id: this.uid++, text: "Learn about Web Components", checked: false },
|
||||
// ];
|
||||
|
||||
constructor(){
|
||||
super();
|
||||
this.uid = 1;
|
||||
this.todos = [
|
||||
{id: this.uid++, text: "my initial todo", checked: false },
|
||||
{id: this.uid++, text: "Learn about Web Components", checked: false },
|
||||
]
|
||||
}
|
||||
@State() todos = [
|
||||
{id: this.uid++, text: "my initial todo", checked: false },
|
||||
{id: this.uid++, text: "Learn about Web Components", checked: false },
|
||||
];
|
||||
|
||||
render(){
|
||||
return (
|
||||
|
||||
111
yarn.lock
111
yarn.lock
@ -26,18 +26,18 @@
|
||||
dependencies:
|
||||
"@babel/highlight" "^7.0.0"
|
||||
|
||||
"@babel/core@^7.6.2":
|
||||
version "7.6.4"
|
||||
resolved "https://registry.npmjs.org/@babel/core/-/core-7.6.4.tgz#6ebd9fe00925f6c3e177bb726a188b5f578088ff"
|
||||
integrity sha512-Rm0HGw101GY8FTzpWSyRbki/jzq+/PkNQJ+nSulrdY6gFGOsNseCqD6KHRYe2E+EdzuBdr2pxCp6s4Uk6eJ+XQ==
|
||||
"@babel/core@7.7.0":
|
||||
version "7.7.0"
|
||||
resolved "https://registry.npmjs.org/@babel/core/-/core-7.7.0.tgz#461d2948b1a7113088baf999499bcbd39a7faa3b"
|
||||
integrity sha512-Bb1NjZCaiwTQC/ARL+MwDpgocdnwWDCaugvkGt6cxfBzQa8Whv1JybBoUEiBDKl8Ni3H3c7Fykwk7QChUsHRlg==
|
||||
dependencies:
|
||||
"@babel/code-frame" "^7.5.5"
|
||||
"@babel/generator" "^7.6.4"
|
||||
"@babel/helpers" "^7.6.2"
|
||||
"@babel/parser" "^7.6.4"
|
||||
"@babel/template" "^7.6.0"
|
||||
"@babel/traverse" "^7.6.3"
|
||||
"@babel/types" "^7.6.3"
|
||||
"@babel/generator" "^7.7.0"
|
||||
"@babel/helpers" "^7.7.0"
|
||||
"@babel/parser" "^7.7.0"
|
||||
"@babel/template" "^7.7.0"
|
||||
"@babel/traverse" "^7.7.0"
|
||||
"@babel/types" "^7.7.0"
|
||||
convert-source-map "^1.1.0"
|
||||
debug "^4.1.0"
|
||||
json5 "^2.1.0"
|
||||
@ -46,7 +46,7 @@
|
||||
semver "^5.4.1"
|
||||
source-map "^0.5.0"
|
||||
|
||||
"@babel/generator@^7.6.3", "@babel/generator@^7.6.4":
|
||||
"@babel/generator@^7.6.3":
|
||||
version "7.6.4"
|
||||
resolved "https://registry.npmjs.org/@babel/generator/-/generator-7.6.4.tgz#a4f8437287bf9671b07f483b76e3bb731bc97671"
|
||||
integrity sha512-jsBuXkFoZxk0yWLyGI9llT9oiQ2FeTASmRFE32U+aaDTfoE92t78eroO7PTpU/OrYq38hlcDM6vbfLDaOLy+7w==
|
||||
@ -56,6 +56,16 @@
|
||||
lodash "^4.17.13"
|
||||
source-map "^0.5.0"
|
||||
|
||||
"@babel/generator@^7.7.0":
|
||||
version "7.7.0"
|
||||
resolved "https://registry.npmjs.org/@babel/generator/-/generator-7.7.0.tgz#c6d4d1f7a0d6e139cbd01aca73170b0bff5425b4"
|
||||
integrity sha512-1wdJ6UxHyL1XoJQ119JmvuRX27LRih7iYStMPZOWAjQqeAabFg3dYXKMpgihma+to+0ADsTVVt6oRyUxWZw6Mw==
|
||||
dependencies:
|
||||
"@babel/types" "^7.7.0"
|
||||
jsesc "^2.5.1"
|
||||
lodash "^4.17.13"
|
||||
source-map "^0.5.0"
|
||||
|
||||
"@babel/helper-annotate-as-pure@^7.0.0":
|
||||
version "7.0.0"
|
||||
resolved "https://registry.npmjs.org/@babel/helper-annotate-as-pure/-/helper-annotate-as-pure-7.0.0.tgz#323d39dd0b50e10c7c06ca7d7638e6864d8c5c32"
|
||||
@ -126,6 +136,15 @@
|
||||
"@babel/template" "^7.1.0"
|
||||
"@babel/types" "^7.0.0"
|
||||
|
||||
"@babel/helper-function-name@^7.7.0":
|
||||
version "7.7.0"
|
||||
resolved "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.7.0.tgz#44a5ad151cfff8ed2599c91682dda2ec2c8430a3"
|
||||
integrity sha512-tDsJgMUAP00Ugv8O2aGEua5I2apkaQO7lBGUq1ocwN3G23JE5Dcq0uh3GvFTChPa4b40AWiAsLvCZOA2rdnQ7Q==
|
||||
dependencies:
|
||||
"@babel/helper-get-function-arity" "^7.7.0"
|
||||
"@babel/template" "^7.7.0"
|
||||
"@babel/types" "^7.7.0"
|
||||
|
||||
"@babel/helper-get-function-arity@^7.0.0":
|
||||
version "7.0.0"
|
||||
resolved "https://registry.npmjs.org/@babel/helper-get-function-arity/-/helper-get-function-arity-7.0.0.tgz#83572d4320e2a4657263734113c42868b64e49c3"
|
||||
@ -133,6 +152,13 @@
|
||||
dependencies:
|
||||
"@babel/types" "^7.0.0"
|
||||
|
||||
"@babel/helper-get-function-arity@^7.7.0":
|
||||
version "7.7.0"
|
||||
resolved "https://registry.npmjs.org/@babel/helper-get-function-arity/-/helper-get-function-arity-7.7.0.tgz#c604886bc97287a1d1398092bc666bc3d7d7aa2d"
|
||||
integrity sha512-tLdojOTz4vWcEnHWHCuPN5P85JLZWbm5Fx5ZsMEMPhF3Uoe3O7awrbM2nQ04bDOUToH/2tH/ezKEOR8zEYzqyw==
|
||||
dependencies:
|
||||
"@babel/types" "^7.7.0"
|
||||
|
||||
"@babel/helper-hoist-variables@^7.4.4":
|
||||
version "7.4.4"
|
||||
resolved "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.4.4.tgz#0298b5f25c8c09c53102d52ac4a98f773eb2850a"
|
||||
@ -221,6 +247,13 @@
|
||||
dependencies:
|
||||
"@babel/types" "^7.4.4"
|
||||
|
||||
"@babel/helper-split-export-declaration@^7.7.0":
|
||||
version "7.7.0"
|
||||
resolved "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.7.0.tgz#1365e74ea6c614deeb56ebffabd71006a0eb2300"
|
||||
integrity sha512-HgYSI8rH08neWlAH3CcdkFg9qX9YsZysZI5GD8LjhQib/mM0jGOZOVkoUiiV2Hu978fRtjtsGsW6w0pKHUWtqA==
|
||||
dependencies:
|
||||
"@babel/types" "^7.7.0"
|
||||
|
||||
"@babel/helper-wrap-function@^7.1.0":
|
||||
version "7.2.0"
|
||||
resolved "https://registry.npmjs.org/@babel/helper-wrap-function/-/helper-wrap-function-7.2.0.tgz#c4e0012445769e2815b55296ead43a958549f6fa"
|
||||
@ -231,14 +264,12 @@
|
||||
"@babel/traverse" "^7.1.0"
|
||||
"@babel/types" "^7.2.0"
|
||||
|
||||
"@babel/helpers@^7.6.2":
|
||||
version "7.6.2"
|
||||
resolved "https://registry.npmjs.org/@babel/helpers/-/helpers-7.6.2.tgz#681ffe489ea4dcc55f23ce469e58e59c1c045153"
|
||||
integrity sha512-3/bAUL8zZxYs1cdX2ilEE0WobqbCmKWr/889lf2SS0PpDcpEIY8pb1CCyz0pEcX3pEb+MCbks1jIokz2xLtGTA==
|
||||
"@babel/helpers@^7.7.0", "@babel/helpers@file:./packages/babel-helpers":
|
||||
version "7.7.0"
|
||||
dependencies:
|
||||
"@babel/template" "^7.6.0"
|
||||
"@babel/traverse" "^7.6.2"
|
||||
"@babel/types" "^7.6.0"
|
||||
"@babel/template" "^7.7.0"
|
||||
"@babel/traverse" "^7.7.0"
|
||||
"@babel/types" "^7.7.0"
|
||||
|
||||
"@babel/highlight@^7.0.0":
|
||||
version "7.5.0"
|
||||
@ -249,11 +280,16 @@
|
||||
esutils "^2.0.2"
|
||||
js-tokens "^4.0.0"
|
||||
|
||||
"@babel/parser@^7.4.4", "@babel/parser@^7.6.0", "@babel/parser@^7.6.3", "@babel/parser@^7.6.4":
|
||||
"@babel/parser@^7.4.4", "@babel/parser@^7.6.0", "@babel/parser@^7.6.3":
|
||||
version "7.6.4"
|
||||
resolved "https://registry.npmjs.org/@babel/parser/-/parser-7.6.4.tgz#cb9b36a7482110282d5cb6dd424ec9262b473d81"
|
||||
integrity sha512-D8RHPW5qd0Vbyo3qb+YjO5nvUVRTXFLQ/FsDxJU2Nqz4uB5EnUN0ZQSEYpvTIbRuttig1XbHWU5oMeQwQSAA+A==
|
||||
|
||||
"@babel/parser@^7.7.0":
|
||||
version "7.7.0"
|
||||
resolved "https://registry.npmjs.org/@babel/parser/-/parser-7.7.0.tgz#232618f6e8947bc54b407fa1f1c91a22758e7159"
|
||||
integrity sha512-GqL+Z0d7B7ADlQBMXlJgvXEbtt5qlqd1YQ5fr12hTSfh7O/vgrEIvJxU2e7aSVrEUn75zTZ6Nd0s8tthrlZnrQ==
|
||||
|
||||
"@babel/plugin-proposal-async-generator-functions@^7.2.0":
|
||||
version "7.2.0"
|
||||
resolved "https://registry.npmjs.org/@babel/plugin-proposal-async-generator-functions/-/plugin-proposal-async-generator-functions-7.2.0.tgz#b289b306669dce4ad20b0252889a15768c9d417e"
|
||||
@ -749,7 +785,7 @@
|
||||
js-levenshtein "^1.1.3"
|
||||
semver "^5.5.0"
|
||||
|
||||
"@babel/template@^7.1.0", "@babel/template@^7.4.4", "@babel/template@^7.6.0":
|
||||
"@babel/template@^7.1.0", "@babel/template@^7.4.4":
|
||||
version "7.6.0"
|
||||
resolved "https://registry.npmjs.org/@babel/template/-/template-7.6.0.tgz#7f0159c7f5012230dad64cca42ec9bdb5c9536e6"
|
||||
integrity sha512-5AEH2EXD8euCk446b7edmgFdub/qfH1SN6Nii3+fyXP807QRx9Q73A2N5hNwRRslC2H9sNzaFhsPubkS4L8oNQ==
|
||||
@ -758,7 +794,16 @@
|
||||
"@babel/parser" "^7.6.0"
|
||||
"@babel/types" "^7.6.0"
|
||||
|
||||
"@babel/traverse@^7.1.0", "@babel/traverse@^7.4.4", "@babel/traverse@^7.5.5", "@babel/traverse@^7.6.2", "@babel/traverse@^7.6.3":
|
||||
"@babel/template@^7.7.0":
|
||||
version "7.7.0"
|
||||
resolved "https://registry.npmjs.org/@babel/template/-/template-7.7.0.tgz#4fadc1b8e734d97f56de39c77de76f2562e597d0"
|
||||
integrity sha512-OKcwSYOW1mhWbnTBgQY5lvg1Fxg+VyfQGjcBduZFljfc044J5iDlnDSfhQ867O17XHiSCxYHUxHg2b7ryitbUQ==
|
||||
dependencies:
|
||||
"@babel/code-frame" "^7.0.0"
|
||||
"@babel/parser" "^7.7.0"
|
||||
"@babel/types" "^7.7.0"
|
||||
|
||||
"@babel/traverse@^7.1.0", "@babel/traverse@^7.4.4", "@babel/traverse@^7.5.5":
|
||||
version "7.6.3"
|
||||
resolved "https://registry.npmjs.org/@babel/traverse/-/traverse-7.6.3.tgz#66d7dba146b086703c0fb10dd588b7364cec47f9"
|
||||
integrity sha512-unn7P4LGsijIxaAJo/wpoU11zN+2IaClkQAxcJWBNCMS6cmVh802IyLHNkAjQ0iYnRS3nnxk5O3fuXW28IMxTw==
|
||||
@ -773,6 +818,21 @@
|
||||
globals "^11.1.0"
|
||||
lodash "^4.17.13"
|
||||
|
||||
"@babel/traverse@^7.7.0":
|
||||
version "7.7.0"
|
||||
resolved "https://registry.npmjs.org/@babel/traverse/-/traverse-7.7.0.tgz#9f5744346b8d10097fd2ec2eeffcaf19813cbfaf"
|
||||
integrity sha512-ea/3wRZc//e/uwCpuBX2itrhI0U9l7+FsrKWyKGNyvWbuMcCG7ATKY2VI4wlg2b2TA39HHwIxnvmXvtiKsyn7w==
|
||||
dependencies:
|
||||
"@babel/code-frame" "^7.5.5"
|
||||
"@babel/generator" "^7.7.0"
|
||||
"@babel/helper-function-name" "^7.7.0"
|
||||
"@babel/helper-split-export-declaration" "^7.7.0"
|
||||
"@babel/parser" "^7.7.0"
|
||||
"@babel/types" "^7.7.0"
|
||||
debug "^4.1.0"
|
||||
globals "^11.1.0"
|
||||
lodash "^4.17.13"
|
||||
|
||||
"@babel/types@^7.0.0", "@babel/types@^7.2.0", "@babel/types@^7.3.0", "@babel/types@^7.4.4", "@babel/types@^7.5.5", "@babel/types@^7.6.0", "@babel/types@^7.6.3":
|
||||
version "7.6.3"
|
||||
resolved "https://registry.npmjs.org/@babel/types/-/types-7.6.3.tgz#3f07d96f854f98e2fbd45c64b0cb942d11e8ba09"
|
||||
@ -782,6 +842,15 @@
|
||||
lodash "^4.17.13"
|
||||
to-fast-properties "^2.0.0"
|
||||
|
||||
"@babel/types@^7.7.0":
|
||||
version "7.7.1"
|
||||
resolved "https://registry.npmjs.org/@babel/types/-/types-7.7.1.tgz#8b08ea368f2baff236613512cf67109e76285827"
|
||||
integrity sha512-kN/XdANDab9x1z5gcjDc9ePpxexkt+1EQ2MQUiM4XnMvQfvp87/+6kY4Ko2maLXH+tei/DgJ/ybFITeqqRwDiA==
|
||||
dependencies:
|
||||
esutils "^2.0.2"
|
||||
lodash "^4.17.13"
|
||||
to-fast-properties "^2.0.0"
|
||||
|
||||
"@nodelib/fs.scandir@2.1.3":
|
||||
version "2.1.3"
|
||||
resolved "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.3.tgz#3a582bdb53804c6ba6d146579c46e52130cf4a3b"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user