* normalize npmignores

* fixup eslint ignore, etc

* lint

* remove unused

* rm from gitignore

* use strict
This commit is contained in:
Henry Zhu
2017-03-25 21:46:16 -04:00
committed by GitHub
parent cff1c8db39
commit 7a1ccf076c
122 changed files with 249 additions and 309 deletions

View File

@@ -1,12 +1,14 @@
var babel = require("../package.json").babel;
var register = require("babel-register");
var path = require("path");
"use strict";
const babel = require("../package.json").babel;
const register = require("babel-register");
const path = require("path");
if (babel.plugins) {
// correct path of relative plugins
babel.plugins = babel.plugins.map(function (plugin) {
if (plugin.charAt(0) === '.') {
return plugin.replace(/^\./, path.join(__dirname, '..'));
if (plugin.charAt(0) === ".") {
return plugin.replace(/^\./, path.join(__dirname, ".."));
}
return plugin;

View File

@@ -1,128 +1,129 @@
'use strict';
"use strict";
var util = require('util');
var path = require('path');
var fs = require('fs');
const util = require("util");
const path = require("path");
const fs = require("fs");
var types = require('../packages/babel-types');
const types = require("../packages/babel-types");
var readmePath = path.join(__dirname, '..', 'packages', 'babel-types', 'README.md');
var readmeSrc = fs.readFileSync(readmePath, 'utf8');
var readme = [
readmeSrc.split('<!-- begin generated section -->')[0].trim(),
'',
'<!-- begin generated section -->',
''
const readmePath = path.join(__dirname, "..", "packages", "babel-types", "README.md");
const readmeSrc = fs.readFileSync(readmePath, "utf8");
const readme = [
readmeSrc.split("<!-- begin generated section -->")[0].trim(),
"",
"<!-- begin generated section -->",
"",
];
var customTypes = {
const customTypes = {
ClassMethod: {
key: 'if computed then `Expression` else `Identifier | Literal`',
key: "if computed then `Expression` else `Identifier | Literal`",
},
Identifier: {
name: '`string`',
name: "`string`",
},
MemberExpression: {
property: 'if computed then `Expression` else `Identifier`',
property: "if computed then `Expression` else `Identifier`",
},
ObjectMethod: {
key: 'if computed then `Expression` else `Identifier | Literal`',
key: "if computed then `Expression` else `Identifier | Literal`",
},
ObjectProperty: {
key: 'if computed then `Expression` else `Identifier | Literal`',
key: "if computed then `Expression` else `Identifier | Literal`",
},
};
function getType(validator) {
if (validator.type) {
return validator.type;
} else if (validator.oneOfNodeTypes) {
return validator.oneOfNodeTypes.join(' | ');
return validator.oneOfNodeTypes.join(" | ");
} else if (validator.oneOfNodeOrValueTypes) {
return validator.oneOfNodeOrValueTypes.join(' | ');
return validator.oneOfNodeOrValueTypes.join(" | ");
} else if (validator.oneOf) {
return validator.oneOf.map(val => util.inspect(val)).join(' | ');
return validator.oneOf.map((val) => util.inspect(val)).join(" | ");
} else if (validator.chainOf) {
if (
validator.chainOf.length === 2 &&
validator.chainOf[0].type === 'array' &&
validator.chainOf[0].type === "array" &&
validator.chainOf[1].each
) {
return 'Array<' + getType(validator.chainOf[1].each) + '>';
return "Array<" + getType(validator.chainOf[1].each) + ">";
}
if (
validator.chainOf.length === 2 &&
validator.chainOf[0].type === 'string' &&
validator.chainOf[0].type === "string" &&
validator.chainOf[1].oneOf
) {
return validator.chainOf[1].oneOf.map(function (val) {
return JSON.stringify(val);
}).join(' | ');
}).join(" | ");
}
}
var err = new Error('Unrecognised validator type');
err.code = 'UNEXPECTED_VALIDATOR_TYPE';
const err = new Error("Unrecognised validator type");
err.code = "UNEXPECTED_VALIDATOR_TYPE";
err.validator = validator;
throw err;
}
Object.keys(types.BUILDER_KEYS).sort().forEach(function (key) {
readme.push('### ' + key[0].toLowerCase() + key.substr(1));
readme.push('```javascript');
readme.push('t.' + key[0].toLowerCase() + key.substr(1) + '(' + types.BUILDER_KEYS[key].join(', ') + ')');
readme.push('```');
readme.push('');
readme.push('See also `t.is' + key + '(node, opts)` and `t.assert' + key + '(node, opts)`.');
readme.push('');
readme.push("### " + key[0].toLowerCase() + key.substr(1));
readme.push("```javascript");
readme.push("t." + key[0].toLowerCase() + key.substr(1) + "(" + types.BUILDER_KEYS[key].join(", ") + ")");
readme.push("```");
readme.push("");
readme.push("See also `t.is" + key + "(node, opts)` and `t.assert" + key + "(node, opts)`.");
readme.push("");
if (types.ALIAS_KEYS[key] && types.ALIAS_KEYS[key].length) {
readme.push('Aliases: ' + types.ALIAS_KEYS[key].map(function (key) {
return '`' + key + '`';
}).join(', '));
readme.push('');
readme.push("Aliases: " + types.ALIAS_KEYS[key].map(function (key) {
return "`" + key + "`";
}).join(", "));
readme.push("");
}
Object.keys(types.NODE_FIELDS[key]).sort(function (fieldA, fieldB) {
var indexA = types.BUILDER_KEYS[key].indexOf(fieldA);
var indexB = types.BUILDER_KEYS[key].indexOf(fieldB);
const indexA = types.BUILDER_KEYS[key].indexOf(fieldA);
const indexB = types.BUILDER_KEYS[key].indexOf(fieldB);
if (indexA === indexB) return fieldA < fieldB ? -1 : 1;
if (indexA === -1) return 1;
if (indexB === -1) return -1;
return indexA - indexB;
})
.forEach(function (field) {
var defaultValue = types.NODE_FIELDS[key][field].default;
var fieldDescription = ['`' + field + '`'];
var validator = types.NODE_FIELDS[key][field].validate;
const defaultValue = types.NODE_FIELDS[key][field].default;
const fieldDescription = ["`" + field + "`"];
const validator = types.NODE_FIELDS[key][field].validate;
if (customTypes[key] && customTypes[key][field]) {
fieldDescription.push(customTypes[key][field]);
} else if (validator) {
try {
fieldDescription.push(': `' + getType(validator) + '`');
fieldDescription.push(": `" + getType(validator) + "`");
} catch (ex) {
if (ex.code !== UNEXPECTED_VALIDATOR_TYPE);
console.log('Unrecognised validator type for ' + key + '.' + field);
console.dir(ex.validator, {depth: 10, colors: true});
if (ex.code === "UNEXPECTED_VALIDATOR_TYPE") {
console.log("Unrecognised validator type for " + key + "." + field);
console.dir(ex.validator, { depth: 10, colors: true });
}
}
}
if (
defaultValue !== null ||
types.NODE_FIELDS[key][field].optional
) {
fieldDescription.push(' (default: `' + util.inspect(defaultValue) + '`)');
fieldDescription.push(" (default: `" + util.inspect(defaultValue) + "`)");
} else {
fieldDescription.push(' (required)');
fieldDescription.push(" (required)");
}
readme.push(' - ' + fieldDescription.join(''));
readme.push(" - " + fieldDescription.join(""));
});
readme.push('');
readme.push('---');
readme.push('');
readme.push("");
readme.push("---");
readme.push("");
});
readme.push(
'',
'<!-- end generated section -->',
'',
readmeSrc.split('<!-- end generated section -->')[1].trim()
"",
"<!-- end generated section -->",
"",
readmeSrc.split("<!-- end generated section -->")[1].trim()
);
fs.writeFileSync(readmePath, readme.join('\n'));
fs.writeFileSync(readmePath, readme.join("\n"));
// console.log(readme.join('\n'));

View File

@@ -1,9 +1,11 @@
var fs = require("fs");
var t = require("../packages/babel-types");
"use strict";
var NODE_PREFIX = "BabelNode";
const fs = require("fs");
const t = require("../packages/babel-types");
var code = `// NOTE: This file is autogenerated. Do not modify.
const NODE_PREFIX = "BabelNode";
let code = `// NOTE: This file is autogenerated. Do not modify.
// See scripts/generate-interfaces.js for script used.
declare class ${NODE_PREFIX}Comment {
@@ -44,23 +46,23 @@ declare class ${NODE_PREFIX} {
//
var lines = [];
const lines = [];
for (var type in t.NODE_FIELDS) {
var fields = t.NODE_FIELDS[type];
for (const type in t.NODE_FIELDS) {
const fields = t.NODE_FIELDS[type];
var struct = ['type: "' + type + '";'];
var args = [];
const struct = ["type: \"" + type + "\";"];
const args = [];
for (var fieldName in fields) {
var field = fields[fieldName];
for (const fieldName in fields) {
const field = fields[fieldName];
var suffix = "";
let suffix = "";
if (field.optional || field.default != null) suffix += "?";
var typeAnnotation = "any";
let typeAnnotation = "any";
var validate = field.validate;
const validate = field.validate;
if (validate) {
if (validate.oneOf) {
typeAnnotation = validate.oneOf.map(function (val) {
@@ -77,7 +79,7 @@ for (var type in t.NODE_FIELDS) {
}
if (validate.oneOfNodeTypes) {
var types = validate.oneOfNodeTypes.map(type => `${NODE_PREFIX}${type}`);
const types = validate.oneOfNodeTypes.map((type) => `${NODE_PREFIX}${type}`);
typeAnnotation = types.join(" | ");
if (suffix === "?") typeAnnotation = "?" + typeAnnotation;
}
@@ -97,18 +99,20 @@ for (var type in t.NODE_FIELDS) {
}\n\n`;
// Flow chokes on super() :/
if (type !== 'Super') {
lines.push(`declare function ${type[0].toLowerCase() + type.slice(1)}(${args.join(", ")}): ${NODE_PREFIX}${type};`);
if (type !== "Super") {
lines.push(
`declare function ${type[0].toLowerCase() + type.slice(1)}(${args.join(", ")}): ${NODE_PREFIX}${type};`
);
}
}
for (var i = 0; i < t.TYPES.length; i++) {
for (let i = 0; i < t.TYPES.length; i++) {
lines.push(`declare function is${t.TYPES[i]}(node: Object, opts?: Object): boolean;`);
}
for (var type in t.FLIPPED_ALIAS_KEYS) {
var types = t.FLIPPED_ALIAS_KEYS[type];
code += `type ${NODE_PREFIX}${type} = ${types.map(type => `${NODE_PREFIX}${type}`).join(" | ")};\n`;
for (const type in t.FLIPPED_ALIAS_KEYS) {
const types = t.FLIPPED_ALIAS_KEYS[type];
code += `type ${NODE_PREFIX}${type} = ${types.map((type) => `${NODE_PREFIX}${type}`).join(" | ")};\n`;
}
code += `\ndeclare module "babel-types" {