Skip to content

Commit

Permalink
Merge branch 'master' into arrow_parens
Browse files Browse the repository at this point in the history
  • Loading branch information
suchipi committed Nov 28, 2017
2 parents d664552 + 172d34e commit 73ac57e
Show file tree
Hide file tree
Showing 44 changed files with 370 additions and 35,570 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/website/node_modules
/website/build
/website/i18n
/website/static/lib
.DS_Store
coverage
.idea
7 changes: 0 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,3 @@ script:
- yarn lint-docs
- AST_COMPARE=1 yarn test -- --runInBand
- if [ "${NODE_ENV}" = "development" ]; then yarn codecov; fi
deploy:
provider: script
script: website/deploy.sh
skip_cleanup: true
on:
branch: master
node: stable
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"emoji-regex": "6.5.1",
"escape-string-regexp": "1.0.5",
"esutils": "2.0.2",
"flow-parser": "0.51.1",
"flow-parser": "0.59.0",
"get-stream": "3.0.0",
"globby": "6.1.0",
"graphql": "0.10.5",
Expand Down Expand Up @@ -72,7 +72,7 @@
"rollup-plugin-node-builtins": "2.0.0",
"rollup-plugin-node-globals": "1.1.0",
"rollup-plugin-node-resolve": "2.0.0",
"rollup-plugin-replace": "1.1.1",
"rollup-plugin-replace": "1.2.1",
"shelljs": "0.7.8",
"strip-ansi": "4.0.0",
"sw-toolbox": "3.6.0",
Expand All @@ -88,6 +88,7 @@
"lint": "cross-env EFF_NO_LINK_RULES=true eslint . --format node_modules/eslint-friendly-formatter",
"lint-docs": "prettylint {.,docs,website}/*.md",
"build": "node ./scripts/build/build.js",
"build-docs": "node ./scripts/build/build-docs.js",
"check-deps": "node ./scripts/check-deps.js"
}
}
81 changes: 81 additions & 0 deletions scripts/build/build-docs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env node

"use strict";

const path = require("path");
const shell = require("shelljs");

const rootDir = path.join(__dirname, "..", "..");
const docs = path.join(rootDir, "website/static/lib");
const parsers = [
"babylon",
"flow",
"typescript",
"graphql",
"postcss",
"parse5",
"markdown"
];

function pipe(string) {
return new shell.ShellString(string);
}

const isPullRequest = process.env.PULL_REQUEST === "true";
const prettierPath = isPullRequest ? "dist" : "node_modules/prettier/";

// --- Build prettier for PR ---

if (isPullRequest) {
const pkg = require("../../package.json");
pkg.version = `preview-${process.env.REVIEW_ID}`;
pipe(JSON.stringify(pkg, null, 2)).to("package.json");
shell.exec("node scripts/build/build.js");
}

// --- Docs ---

shell.mkdir("-p", docs);

shell.echo("Bundling docs index...");
shell.cp(`${prettierPath}/index.js`, `${docs}/index.js`);
shell.exec(
`node_modules/babel-cli/bin/babel.js ${docs}/index.js --out-file ${
docs
}/index.js --presets=es2015`
);

shell.echo("Bundling docs babylon...");
shell.exec(
`rollup -c scripts/build/rollup.docs.config.js --environment filepath:parser-babylon.js -i ${
prettierPath
}/parser-babylon.js`
);
shell.exec(
`node_modules/babel-cli/bin/babel.js ${docs}/parser-babylon.js --out-file ${
docs
}/parser-babylon.js --presets=es2015`
);

for (const parser of parsers) {
if (parser === "babylon") {
continue;
}
shell.echo(`Bundling docs ${parser}...`);
shell.exec(
`rollup -c scripts/build/rollup.docs.config.js --environment filepath:parser-${
parser
}.js -i ${prettierPath}/parser-${parser}.js`
);
}

shell.echo("Copy sw-toolbox.js to docs");
shell.cp("node_modules/sw-toolbox/sw-toolbox.js", `${docs}/sw-toolbox.js`);

// --- Site ---
shell.cd("website");
shell.echo("Building website...");
shell.exec("yarn install");
shell.exec("yarn build");

shell.echo();
45 changes: 1 addition & 44 deletions scripts/build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const formatMarkdown = require("../../website/static/markdown");
const shell = require("shelljs");

const rootDir = path.join(__dirname, "..", "..");
const docs = path.join(rootDir, "website/static/lib");
const parsers = [
"babylon",
"flow",
Expand All @@ -28,8 +27,7 @@ function pipe(string) {
shell.set("-e");
shell.cd(rootDir);

shell.rm("-Rf", "dist/", docs);
shell.mkdir("-p", docs);
shell.rm("-Rf", "dist/");

// --- Lib ---

Expand Down Expand Up @@ -66,44 +64,6 @@ pipe(`module.exports = ${content}`).to("dist/parser-postcss.js");

shell.echo();

// --- Docs ---

shell.echo("Bundling docs index...");
shell.exec(
`rollup -c scripts/build/rollup.index.config.js --environment BUILD_TARGET:website -o ${
docs
}/index.js`
);
shell.exec(
`node_modules/babel-cli/bin/babel.js ${docs}/index.js --out-file ${
docs
}/index.js --presets=es2015`
);

shell.echo("Bundling docs babylon...");
shell.exec(
"rollup -c scripts/build/rollup.docs.config.js --environment filepath:parser-babylon.js"
);
shell.exec(
`node_modules/babel-cli/bin/babel.js ${docs}/parser-babylon.js --out-file ${
docs
}/parser-babylon.js --presets=es2015`
);

for (const parser of parsers) {
if (parser === "babylon") {
continue;
}
shell.echo(`Bundling docs ${parser}...`);
shell.exec(
`rollup -c scripts/build/rollup.docs.config.js --environment filepath:parser-${
parser
}.js`
);
}

shell.echo();

// --- Misc ---

shell.echo("Remove eval");
Expand Down Expand Up @@ -133,9 +93,6 @@ const newIssueTemplate = issueTemplate.replace(
);
pipe(newIssueTemplate).to(".github/ISSUE_TEMPLATE.md");

shell.echo("Copy sw-toolbox.js to docs");
shell.cp("node_modules/sw-toolbox/sw-toolbox.js", `${docs}/sw-toolbox.js`);

shell.echo("Copy package.json");
const pkgWithoutDependencies = Object.assign({}, pkg);
delete pkgWithoutDependencies.dependencies;
Expand Down
2 changes: 1 addition & 1 deletion scripts/build/rollup.docs.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const filename = filepath.replace(/.+\//, "");
const basename = filename.replace(/\..+/, "");

export default Object.assign(baseConfig, {
entry: "dist/" + filepath,
entry: "node_modules/prettier/" + filepath,
dest: "website/static/lib/" + filename,
format: "iife",
plugins: [json(), resolve({ preferBuiltins: true }), commonjs(), globals()],
Expand Down
9 changes: 9 additions & 0 deletions scripts/build/rollup.parser.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ export default Object.assign(baseConfig, {
include: "node_modules/typescript-eslint-parser/parser.js"
})
: {},
// In flow-parser 0.59.0 there's a dynamic require: `require(s8)` which not
// supported by rollup-plugin-commonjs, so we have to replace the variable
// by its value before bundling.
parser === "flow"
? replace({
"require(s8)": 'require("fs")',
include: "node_modules/flow-parser/flow_parser.js"
})
: {},
json(),
resolve({ preferBuiltins: true }),
commonjs(),
Expand Down
7 changes: 2 additions & 5 deletions src/clean-ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ function massageAST(ast, parent) {
(ast.type === "value-word" && ast.isColor && ast.isHex) ||
ast.type === "media-feature" ||
ast.type === "selector-root-invalid" ||
ast.type === "selector-tag" ||
ast.type === "selector-pseudo"
) {
newObj.value = newObj.value.toLowerCase();
Expand All @@ -99,9 +98,6 @@ function massageAST(ast, parent) {
if (ast.type === "css-atrule" || ast.type === "css-import") {
newObj.name = newObj.name.toLowerCase();
}
if (ast.type === "selector-attribute") {
newObj.attribute = newObj.attribute.toLowerCase();
}
if (ast.type === "value-number") {
newObj.unit = newObj.unit.toLowerCase();
}
Expand Down Expand Up @@ -139,7 +135,8 @@ function massageAST(ast, parent) {
ast.type === "value-number" ||
ast.type === "selector-root-invalid" ||
ast.type === "selector-class" ||
ast.type === "selector-combinator") &&
ast.type === "selector-combinator" ||
ast.type === "selector-tag") &&
newObj.value
) {
newObj.value = newObj.value.replace(
Expand Down
6 changes: 6 additions & 0 deletions src/fast-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ FastPath.prototype.needsParens = function(options) {
(node.type === "TSTypeAssertionExpression" ||
node.type === "TSAsExpression")
);
case "Decorator":
return (
parent.expression === node &&
(node.type === "TSTypeAssertionExpression" ||
node.type === "TSAsExpression")
);

case "BinaryExpression":
case "LogicalExpression": {
Expand Down
1 change: 1 addition & 0 deletions src/multiparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const concat = docBuilders.concat;
function printSubtree(subtreeParser, path, print, options) {
const next = Object.assign({}, { transformDoc: doc => doc }, subtreeParser);
next.options = Object.assign({}, options, next.options, {
parentParser: options.parser,
originalText: next.text
});
if (next.options.parser === "json") {
Expand Down
9 changes: 2 additions & 7 deletions src/printer-postcss.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,7 @@ function genericPrint(path, options, print) {
return adjustStrings(n.value, options);
}
case "selector-tag": {
const parent = path.getParentNode();
const index = parent.nodes.indexOf(n);
const previous = index > 0 ? parent.nodes[index - 1] : null;
return previous && previous.type === "selector-nesting"
? n.value
: maybeToLowerCase(n.value);
return adjustNumbers(n.value);
}
case "selector-id": {
return concat(["#", n.value]);
Expand All @@ -238,7 +233,7 @@ function genericPrint(path, options, print) {
case "selector-attribute": {
return concat([
"[",
maybeToLowerCase(n.attribute),
n.attribute,
n.operator ? n.operator : "",
n.value
? quoteAttributeValue(adjustStrings(n.value, options), options)
Expand Down
26 changes: 24 additions & 2 deletions src/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,11 @@ function genericPrintNoParens(path, options, print, args) {
if (n.directive) {
return concat([nodeStr(n.expression, options, true), semi]);
}
return concat([path.call(print, "expression"), semi]); // Babel extension.
// Do not append semicolon after the only JSX element in a program
return concat([
path.call(print, "expression"),
isTheOnlyJSXElementInMarkdown(options, path) ? "" : semi
]); // Babel extension.
case "ParenthesizedExpression":
return concat(["(", path.call(print, "expression"), ")"]);
case "AssignmentExpression":
Expand Down Expand Up @@ -2840,10 +2844,12 @@ function printStatementSequence(path, options, print) {
const parts = [];

// in no-semi mode, prepend statement with semicolon if it might break ASI
// don't prepend the only JSX element in a program with semicolon
if (
!options.semi &&
!isClass &&
stmtNeedsASIProtection(stmtPath, options)
!isTheOnlyJSXElementInMarkdown(options, stmtPath) &&
stmtNeedsASIProtection(stmtPath)
) {
if (stmt.comments && stmt.comments.some(comment => comment.leading)) {
parts.push(print(stmtPath, { needsSemi: true }));
Expand Down Expand Up @@ -5110,4 +5116,20 @@ function printAstToDoc(ast, options, addAlignmentSize) {
return doc;
}

function isTheOnlyJSXElementInMarkdown(options, path) {
if (options.parentParser !== "markdown") {
return false;
}

const node = path.getNode();

if (!node.expression || node.expression.type !== "JSXElement") {
return false;
}

const parent = path.getParentNode();

return parent.type === "Program" && parent.body.length == 1;
}

module.exports = { printAstToDoc };
3 changes: 1 addition & 2 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -683,8 +683,7 @@ function splitText(text) {

text
.replace(new RegExp(`(${cjkPattern})\n(${cjkPattern})`, "g"), "$1$2")
// `\s` but exclude full-width whitspace (`\u3000`)
.split(/([^\S\u3000]+)/)
.split(/([ \t\n]+)/)
.forEach((token, index, tokens) => {
// whitespace
if (index % 2 === 1) {
Expand Down

0 comments on commit 73ac57e

Please sign in to comment.