Merge pull request #6356 from JeromeFitz/babel-messages-inline
Remove babel-messages and inline the usages
This commit is contained in:
commit
6816b26994
@ -28,7 +28,6 @@
|
||||
"babel-code-frame": "7.0.0-beta.2",
|
||||
"babel-generator": "7.0.0-beta.2",
|
||||
"babel-helpers": "7.0.0-beta.2",
|
||||
"babel-messages": "7.0.0-beta.2",
|
||||
"babel-template": "7.0.0-beta.2",
|
||||
"babel-traverse": "7.0.0-beta.2",
|
||||
"babel-types": "7.0.0-beta.2",
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
|
||||
import * as context from "../index";
|
||||
import Plugin from "./plugin";
|
||||
import * as messages from "babel-messages";
|
||||
import defaults from "lodash/defaults";
|
||||
import merge from "lodash/merge";
|
||||
import removed from "./removed";
|
||||
@ -334,7 +333,7 @@ function instantiatePlugin({ value: pluginObj, descriptor }) {
|
||||
Object.keys(pluginObj).forEach(key => {
|
||||
if (!ALLOWED_PLUGIN_KEYS.has(key)) {
|
||||
throw new Error(
|
||||
messages.get("pluginInvalidProperty", descriptor.alias, key),
|
||||
`Plugin ${descriptor.alias} provided an invalid property of ${key}`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@ -5,7 +5,6 @@ export { resolvePlugin, resolvePreset } from "./config/loading/files";
|
||||
export { version } from "../package";
|
||||
export { getEnv } from "./config/helpers/environment";
|
||||
|
||||
export * as messages from "babel-messages";
|
||||
export * as types from "babel-types";
|
||||
export traverse from "babel-traverse";
|
||||
export template from "babel-template";
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import * as helpers from "babel-helpers";
|
||||
import generator from "babel-generator";
|
||||
import * as messages from "babel-messages";
|
||||
import template from "babel-template";
|
||||
import * as t from "babel-types";
|
||||
|
||||
@ -178,7 +177,7 @@ export default function(
|
||||
if (build) {
|
||||
tree = build(namespace, builder);
|
||||
} else {
|
||||
throw new Error(messages.get("unsupportedOutputType", outputType));
|
||||
throw new Error(`Unsupported output type ${outputType}`);
|
||||
}
|
||||
|
||||
return generator(tree).code;
|
||||
|
||||
@ -11,7 +11,6 @@
|
||||
"lib"
|
||||
],
|
||||
"dependencies": {
|
||||
"babel-messages": "7.0.0-beta.2",
|
||||
"babel-types": "7.0.0-beta.2",
|
||||
"jsesc": "^2.5.1",
|
||||
"lodash": "^4.2.0",
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import SourceMap from "./source-map";
|
||||
import * as messages from "babel-messages";
|
||||
import Printer, { type Format } from "./printer";
|
||||
|
||||
/**
|
||||
@ -74,7 +73,8 @@ function normalizeOptions(code, opts): Format {
|
||||
|
||||
if (format.compact) {
|
||||
console.error(
|
||||
"[BABEL] " + messages.get("codeGeneratorDeopt", opts.filename, "500KB"),
|
||||
"[BABEL] Note: The code generator has deoptimised the styling of " +
|
||||
`${opts.filename} as it exceeds the max of ${"500KB"}.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,7 +7,6 @@
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"babel-helper-optimise-call-expression": "7.0.0-beta.2",
|
||||
"babel-messages": "7.0.0-beta.2",
|
||||
"babel-template": "7.0.0-beta.2",
|
||||
"babel-traverse": "7.0.0-beta.2",
|
||||
"babel-types": "7.0.0-beta.2"
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import type { NodePath, Scope } from "babel-traverse";
|
||||
import optimiseCall from "babel-helper-optimise-call-expression";
|
||||
import * as messages from "babel-messages";
|
||||
import * as t from "babel-types";
|
||||
|
||||
// ✌️
|
||||
@ -251,7 +250,7 @@ export default class ReplaceSupers {
|
||||
const node = path.node;
|
||||
|
||||
if (isIllegalBareSuper(node, parent)) {
|
||||
throw path.buildCodeFrameError(messages.get("classesIllegalBareSuper"));
|
||||
throw path.buildCodeFrameError("Illegal use of bare super");
|
||||
}
|
||||
|
||||
if (t.isCallExpression(node)) {
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
src
|
||||
test
|
||||
*.log
|
||||
@ -1,18 +0,0 @@
|
||||
# babel-messages
|
||||
|
||||
> Collection of debug messages used by Babel.
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
npm install --save-dev babel-messages
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import * as messages from 'babel-messages';
|
||||
|
||||
messages.get('tailCallReassignmentDeopt');
|
||||
// > "Function reference has been..."
|
||||
```
|
||||
@ -1,10 +0,0 @@
|
||||
{
|
||||
"name": "babel-messages",
|
||||
"version": "7.0.0-beta.2",
|
||||
"description": "Collection of debug messages used by Babel.",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
"license": "MIT",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-messages",
|
||||
"main": "lib/index.js"
|
||||
}
|
||||
@ -1,96 +0,0 @@
|
||||
/* eslint max-len: "off" */
|
||||
|
||||
import * as util from "util";
|
||||
|
||||
/**
|
||||
* Mapping of messages to be used in Babel.
|
||||
* Messages can include $0-style placeholders.
|
||||
*/
|
||||
|
||||
export const MESSAGES = {
|
||||
tailCallReassignmentDeopt:
|
||||
"Function reference has been reassigned, so it will probably be dereferenced, therefore we can't optimise this with confidence",
|
||||
classesIllegalBareSuper: "Illegal use of bare super",
|
||||
classesIllegalSuperCall:
|
||||
"Direct super call is illegal in non-constructor, use super.$1() instead",
|
||||
scopeDuplicateDeclaration: "Duplicate declaration $1",
|
||||
settersNoRest: "Setters aren't allowed to have a rest",
|
||||
noAssignmentsInForHead: "No assignments allowed in for-in/of head",
|
||||
expectedMemberExpressionOrIdentifier:
|
||||
"Expected type MemberExpression or Identifier",
|
||||
invalidParentForThisNode:
|
||||
"We don't know how to handle this node within the current parent - please open an issue",
|
||||
readOnly: "$1 is read-only",
|
||||
unknownForHead: "Unknown node type $1 in ForStatement",
|
||||
didYouMean: "Did you mean $1?",
|
||||
codeGeneratorDeopt:
|
||||
"Note: The code generator has deoptimised the styling of $1 as it exceeds the max of $2.",
|
||||
missingTemplatesDirectory:
|
||||
"no templates directory - this is most likely the result of a broken `npm publish`. Please report to https://github.com/babel/babel/issues",
|
||||
unsupportedOutputType: "Unsupported output type $1",
|
||||
illegalMethodName: "Illegal method name $1",
|
||||
lostTrackNodePath:
|
||||
"We lost track of this node's position, likely because the AST was directly manipulated",
|
||||
|
||||
modulesIllegalExportName: "Illegal export $1",
|
||||
modulesDuplicateDeclarations:
|
||||
"Duplicate module declarations with the same source but in different scopes",
|
||||
|
||||
undeclaredVariable: "Reference to undeclared variable $1",
|
||||
undeclaredVariableType:
|
||||
"Referencing a type alias outside of a type annotation",
|
||||
undeclaredVariableSuggestion:
|
||||
"Reference to undeclared variable $1 - did you mean $2?",
|
||||
|
||||
traverseNeedsParent:
|
||||
"You must pass a scope and parentPath unless traversing a Program/File. Instead of that you tried to traverse a $1 node without passing scope and parentPath.",
|
||||
traverseVerifyRootFunction:
|
||||
"You passed `traverse()` a function when it expected a visitor object, are you sure you didn't mean `{ enter: Function }`?",
|
||||
traverseVerifyVisitorProperty:
|
||||
"You passed `traverse()` a visitor object with the property $1 that has the invalid property $2",
|
||||
traverseVerifyNodeType:
|
||||
"You gave us a visitor for the node type $1 but it's not a valid type",
|
||||
|
||||
pluginNotObject:
|
||||
"Plugin $2 specified in $1 was expected to return an object when invoked but returned $3",
|
||||
pluginNotFunction:
|
||||
"Plugin $2 specified in $1 was expected to return a function but returned $3",
|
||||
pluginUnknown:
|
||||
"Unknown plugin $1 specified in $2 at $3, attempted to resolve relative to $4",
|
||||
pluginInvalidProperty: "Plugin $1 provided an invalid property of $2",
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a message with $0 placeholders replaced by arguments.
|
||||
*/
|
||||
|
||||
export function get(key: string, ...args: Array<any>): string {
|
||||
const msg = MESSAGES[key];
|
||||
if (!msg) throw new ReferenceError(`Unknown message ${JSON.stringify(key)}`);
|
||||
|
||||
// stringify args
|
||||
args = parseArgs(args);
|
||||
|
||||
// replace $0 placeholders with args
|
||||
return msg.replace(/\$(\d+)/g, function(str, i) {
|
||||
return args[i - 1];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Stingify arguments to be used inside messages.
|
||||
*/
|
||||
|
||||
export function parseArgs(args: Array<any>): Array<string> {
|
||||
return args.map(function(val) {
|
||||
if (val != null && val.inspect) {
|
||||
return val.inspect();
|
||||
} else {
|
||||
try {
|
||||
return JSON.stringify(val) || val + "";
|
||||
} catch (e) {
|
||||
return util.inspect(val);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
export default function({ messages, types: t }) {
|
||||
export default function({ types: t }) {
|
||||
/**
|
||||
* Helper function to run a statement before an expression by replacing it with a comma expression
|
||||
* and wrapping the statement in an IIFE as the first operand.
|
||||
@ -23,7 +23,7 @@ export default function({ messages, types: t }) {
|
||||
for (const violation of (binding.constantViolations: Array)) {
|
||||
const throwNode = t.throwStatement(
|
||||
t.newExpression(t.identifier("Error"), [
|
||||
t.stringLiteral(messages.get("readOnly", name)),
|
||||
t.stringLiteral(`"${name}" is read-only`),
|
||||
]),
|
||||
);
|
||||
|
||||
|
||||
@ -11,7 +11,6 @@
|
||||
"babel-helper-function-name": "7.0.0-beta.2",
|
||||
"babel-helper-optimise-call-expression": "7.0.0-beta.2",
|
||||
"babel-helper-replace-supers": "7.0.0-beta.2",
|
||||
"babel-messages": "7.0.0-beta.2",
|
||||
"babel-template": "7.0.0-beta.2",
|
||||
"babel-traverse": "7.0.0-beta.2",
|
||||
"babel-types": "7.0.0-beta.2"
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
export default function({ messages, template, types: t }) {
|
||||
export default function({ template, types: t }) {
|
||||
const buildForOfArray = template(`
|
||||
for (var KEY = 0; KEY < ARR.length; KEY++) BODY;
|
||||
`);
|
||||
@ -169,7 +169,7 @@ export default function({ messages, template, types: t }) {
|
||||
} else {
|
||||
throw file.buildCodeFrameError(
|
||||
left,
|
||||
messages.get("unknownForHead", left.type),
|
||||
`Unknown node type ${left.type} in ForStatement`,
|
||||
);
|
||||
}
|
||||
|
||||
@ -226,7 +226,7 @@ export default function({ messages, template, types: t }) {
|
||||
} else {
|
||||
throw file.buildCodeFrameError(
|
||||
left,
|
||||
messages.get("unknownForHead", left.type),
|
||||
`Unknown node type ${left.type} in ForStatement`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -10,7 +10,6 @@
|
||||
"dependencies": {
|
||||
"babel-code-frame": "7.0.0-beta.2",
|
||||
"babel-helper-function-name": "7.0.0-beta.2",
|
||||
"babel-messages": "7.0.0-beta.2",
|
||||
"babel-types": "7.0.0-beta.2",
|
||||
"babylon": "7.0.0-beta.26",
|
||||
"debug": "^3.0.1",
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import TraversalContext from "./context";
|
||||
import * as visitors from "./visitors";
|
||||
import * as messages from "babel-messages";
|
||||
import includes from "lodash/includes";
|
||||
import * as t from "babel-types";
|
||||
import * as cache from "./cache";
|
||||
@ -22,7 +21,11 @@ export default function traverse(
|
||||
|
||||
if (!opts.noScope && !scope) {
|
||||
if (parent.type !== "Program" && parent.type !== "File") {
|
||||
throw new Error(messages.get("traverseNeedsParent", parent.type));
|
||||
throw new Error(
|
||||
"You must pass a scope and parentPath unless traversing a Program/File. " +
|
||||
`Instead of that you tried to traverse a ${parent.type} node without ` +
|
||||
"passing scope and parentPath.",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -4,7 +4,6 @@ import Renamer from "./lib/renamer";
|
||||
import type NodePath from "../path";
|
||||
import traverse from "../index";
|
||||
import defaults from "lodash/defaults";
|
||||
import * as messages from "babel-messages";
|
||||
import Binding from "./binding";
|
||||
import globals from "globals";
|
||||
import * as t from "babel-types";
|
||||
@ -361,7 +360,7 @@ export default class Scope {
|
||||
if (duplicate) {
|
||||
throw this.hub.file.buildCodeFrameError(
|
||||
id,
|
||||
messages.get("scopeDuplicateDeclaration", name),
|
||||
`Duplicate declaration "${name}"`,
|
||||
TypeError,
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import * as virtualTypes from "./path/lib/virtual-types";
|
||||
import * as messages from "babel-messages";
|
||||
import * as t from "babel-types";
|
||||
import clone from "lodash/clone";
|
||||
|
||||
@ -125,7 +124,10 @@ export function verify(visitor) {
|
||||
if (visitor._verified) return;
|
||||
|
||||
if (typeof visitor === "function") {
|
||||
throw new Error(messages.get("traverseVerifyRootFunction"));
|
||||
throw new Error(
|
||||
"You passed `traverse()` a function when it expected a visitor object, " +
|
||||
"are you sure you didn't mean `{ enter: Function }`?",
|
||||
);
|
||||
}
|
||||
|
||||
for (const nodeType in visitor) {
|
||||
@ -136,7 +138,9 @@ export function verify(visitor) {
|
||||
if (shouldIgnoreKey(nodeType)) continue;
|
||||
|
||||
if (t.TYPES.indexOf(nodeType) < 0) {
|
||||
throw new Error(messages.get("traverseVerifyNodeType", nodeType));
|
||||
throw new Error(
|
||||
`You gave us a visitor for the node type ${nodeType} but it's not a valid type`,
|
||||
);
|
||||
}
|
||||
|
||||
const visitors = visitor[nodeType];
|
||||
@ -150,7 +154,8 @@ export function verify(visitor) {
|
||||
);
|
||||
} else {
|
||||
throw new Error(
|
||||
messages.get("traverseVerifyVisitorProperty", nodeType, visitorKey),
|
||||
"You passed `traverse()` a visitor object with the property " +
|
||||
`${nodeType} that has the invalid property ${visitorKey}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user