Merge branch 'master' into next
This commit is contained in:
208 files changed
+3936
-797
No files matched your search
+3
-1
@@ -105,6 +105,8 @@ overrides:
|
||||
- files: src/**/*.js
|
||||
rules:
|
||||
prettier-internal-rules/prefer-fast-path-each: error
|
||||
- files: src/language-js/**/*.js
|
||||
- files:
|
||||
- src/language-js/**/*.js
|
||||
- src/language-css/**/*.js
|
||||
rules:
|
||||
prettier-internal-rules/directly-loc-start-end: error
|
||||
@@ -30,7 +30,7 @@ jobs:
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2.3.3
|
||||
uses: actions/checkout@v2.3.4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v2.1.2
|
||||
|
||||
@@ -44,7 +44,7 @@ jobs:
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2.3.3
|
||||
uses: actions/checkout@v2.3.4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v2.1.2
|
||||
|
||||
@@ -14,7 +14,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2.3.3
|
||||
uses: actions/checkout@v2.3.4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v2.1.2
|
||||
|
||||
@@ -14,7 +14,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2.3.3
|
||||
uses: actions/checkout@v2.3.4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v2.1.2
|
||||
@@ -58,7 +58,7 @@ jobs:
|
||||
needs: [build]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2.3.3
|
||||
uses: actions/checkout@v2.3.4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v2.1.2
|
||||
@@ -106,7 +106,7 @@ jobs:
|
||||
needs: [build]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2.3.3
|
||||
uses: actions/checkout@v2.3.4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v2.1.2
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#### [HIGHLIGHT]ESM standalone bundles ([#8983](https://github.com/prettier/prettier/pull/8983) by [@Monchi](https://github.com/Monchi), [@fisker](https://github.com/fisker))
|
||||
|
||||
Now standalone is also bundled as ESM. It works directly on browser.
|
||||
Prettier now also comes as ES modules, which can be directly used in modern browsers:
|
||||
|
||||
```js
|
||||
import prettier from "https://unpkg.com/prettier/esm/standalone.mjs";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#### Fix error on dir or file that name is a number (#9298 by @fisker)
|
||||
#### Fix: error on directories and files with numeric names (#9298 by @fisker)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```console
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#### Improve custom properties format (#9209 by @fisker)
|
||||
#### Improve formatting for custom properties (#9209 by @fisker)
|
||||
|
||||
Thanks to [`PostCSS 8.0`](https://github.com/postcss/postcss/releases/tag/8.0.0), we can handle these edge cases on custom properties.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#### Flow Enums with unknown members (#9432 by @gkz)
|
||||
#### Enums with unknown members (#9432 by @gkz)
|
||||
|
||||
Previously, was not supported. Now, the following is formatted:
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
#### Flow `this` annotations (#9457 by @dsainati1, #9489 by @fisker)
|
||||
|
||||
Add support for `this` parameter annotations in Flow.
|
||||
#### `this` parameter annotations (#9457 by @dsainati1, #9489 by @fisker)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```jsx
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#### Treat more types as "simple" type (#9543 by @fisker)
|
||||
#### Treat more simple types as non-breaking in generic type annotations (#9543 by @fisker)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```jsx
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
#### [HIGHLIGHT]Add `espree` parser (#9000 by @fisker)
|
||||
#### [HIGHLIGHT]Add `espree` and `meriyah` parser (#9000, #9514 by @fisker)
|
||||
|
||||
A new value for the `parser` option has been added: [`espree`](https://github.com/eslint/espree) - which is the [`ESLint`](https://github.com/eslint/eslint) default parser.
|
||||
Two new values for the `parser` option has been added:
|
||||
|
||||
Note that `espree` only works for [ECMAScript Finished Proposals](https://github.com/tc39/proposals/blob/master/finished-proposals.md), and is stricter than the `babel` parser.
|
||||
- [`espree`](https://github.com/eslint/espree) - which is the default parser used by [`ESLint`](https://github.com/eslint/eslint).
|
||||
|
||||
Note that `espree` only works for [Finished ECMAScript Proposals](https://github.com/tc39/proposals/blob/master/finished-proposals.md), and is stricter than the `babel` parser.
|
||||
|
||||
- [`meriyah`](https://github.com/meriyah/meriyah) - A [fast](https://meriyah.github.io/meriyah/performance/) JavaScript parser, successor of [cherow](https://github.com/cherow/cherow).
|
||||
@@ -1,4 +1,4 @@
|
||||
#### Fix comments inside template (#9278 by @fisker)
|
||||
#### Fix comments inside template literals with embedded syntax (#9278 by @fisker)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```js
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#### Improve formatting for `AssignmentExpression` with `ClassExpression` that has a long super class (#9341 by @sosukesuzuki)
|
||||
#### Improve formatting for assignments of classes with long superclass names (#9341 by @sosukesuzuki)
|
||||
|
||||
This improves the formatting for [Google Closure Library Namespace](https://developers.google.com/closure/library/docs/introduction#names).
|
||||
This improves the formatting for [Google Closure Library namespaces](https://developers.google.com/closure/library/docs/introduction#names).
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```js
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#### Fix placing leading comments for a body of while statement (#9345 by @sosukesuzuki)
|
||||
#### Fix placement of leading comments for bodies of `while` statements (#9345 by @sosukesuzuki)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```js
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#### Update to `@babel/parser` 7.12 (#9408, #9476 by @sosukesuzuki)
|
||||
#### Update to `@babel/parser` 7.12 (#9408, #9476, #9597 by @sosukesuzuki)
|
||||
|
||||
Updated the JavaScript parser to [`@babel/parser` 7.12](https://babeljs.io/blog/2020/10/15/7.12.0). This fixes several bugs and supports some new syntax.
|
||||
|
||||
@@ -7,15 +7,11 @@ Updated the JavaScript parser to [`@babel/parser` 7.12](https://babeljs.io/blog/
|
||||
[The "module attributes" proposal supported on 2.1](https://prettier.io/blog/2020/08/24/2.1.0.html#support-es-module-attributes-and-json-modules-8436httpsgithubcomprettierprettierpull8436-by-fiskerhttpsgithubcomfisker) has been significantly changed and also renamed to "import assertions".
|
||||
|
||||
```js
|
||||
import json from "./foo.json" assert { type: "json" };
|
||||
import foo from "./foo.json" assert { type: "json" };
|
||||
```
|
||||
|
||||
##### Support imports and exports with string names
|
||||
|
||||
<!-- TODO: Remove if the bug is fixed -->
|
||||
|
||||
Due to a [bug in `@babel/parser`](https://github.com/babel/babel/issues/12209), Prettier can only use exports, but that will be fixed.
|
||||
|
||||
```js
|
||||
let happy = "happy";
|
||||
export { happy as "😃" };
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#### Keep html and markdown invalid template literals as it is (#9431 by @fisker)
|
||||
#### Keep HTML and Markdown invalid template literals as is (#9431 by @fisker)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```js
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#### Fix `import {a as a}` and `export {a as a}` format (#9435 by @fisker)
|
||||
#### Fix formatting for `import {a as a}` and `export {a as a}` (#9435 by @fisker)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```js
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#### Fix missing blank lines in fenced code block without end mark ([#8786](https://github.com/prettier/prettier/pull/8786) by [@fisker](https://github.com/fisker))
|
||||
#### Fix missing blank lines in fenced code blocks lacking the closing fence ([#8786](https://github.com/prettier/prettier/pull/8786) by [@fisker](https://github.com/fisker))
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```markdown
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#### Add support for [[wiki-style]] links in markdown (#9275 by @iamrecursion)
|
||||
#### Add support for `[[wiki-style]]` links (#9275 by @iamrecursion)
|
||||
|
||||
1. Support for `[[wiki-style]]` links ensures that they do not get broken by
|
||||
the prettier formatting by being wrapped over multiple lines.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#### Fix JSX format (#9267 by @fisker)
|
||||
#### Fix extra empty lines in JSX (#9267 by @fisker)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```markdown
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#### Preserve a last separator for ignored object and interface types (#9318 by @sosukesuzuki)
|
||||
#### Preserve the last separator in ignored object types and interfaces (#9318 by @sosukesuzuki)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```ts
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#### Add parens to object value that it's an assignment (#9484 by @fisker)
|
||||
#### Add parens around assignments in object literal properties (#9484 by @fisker)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```ts
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#### Fix inconsistent type format between `typescript` and `flow` (#9521 by @fisker)
|
||||
#### Fix inconsistencies in formatting of types between `typescript` and `flow` (#9521 by @fisker)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```ts
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#### Fix inconsistent `v-for` format (#9225 by @zweimach)
|
||||
#### Fix inconsistent formatting for `v-for` (#9225 by @zweimach)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```vue
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
"camelcase",
|
||||
"camelified",
|
||||
"chedeau",
|
||||
"cherow",
|
||||
"chrzosel",
|
||||
"Clemmons",
|
||||
"cliify",
|
||||
@@ -212,6 +213,7 @@
|
||||
"mdast",
|
||||
"Memberish",
|
||||
"memoized",
|
||||
"meriyah",
|
||||
"Michał",
|
||||
"Microsyntax",
|
||||
"Mikael",
|
||||
@@ -222,6 +224,7 @@
|
||||
"mixins",
|
||||
"mjml",
|
||||
"mkdir",
|
||||
"mobx",
|
||||
"Moeller",
|
||||
"Monteiro",
|
||||
"Morrell",
|
||||
@@ -394,6 +397,7 @@
|
||||
"Vue's",
|
||||
"Wadler",
|
||||
"Wadler's",
|
||||
"webcompat",
|
||||
"webstorm",
|
||||
"Weixin",
|
||||
"whitespaces",
|
||||
|
||||
+7
-2
@@ -3,13 +3,18 @@ id: browser
|
||||
title: Browser
|
||||
---
|
||||
|
||||
Run Prettier in the browser with the `standalone.js` UMD bundle shipped in the NPM package (starting in version 1.13). The UMD bundle only formats the code and has no support for config files, ignore files, CLI usage, or automatic loading of plugins.
|
||||
Run Prettier in the browser using its **standalone** version. This version only formats the code and has no support for config files, ignore files, CLI usage, or automatic loading of plugins.
|
||||
|
||||
The standalone version comes as:
|
||||
|
||||
- ES modules: `esm/standalone.mjs`, starting in version 2.2
|
||||
- UMD: `standalone.js`, starting in version 1.13
|
||||
|
||||
The [`browser` field](https://github.com/defunctzombie/package-browser-field-spec) in Prettier’s `package.json` points to `standalone.js`. That’s why you can just `import` or `require` the `prettier` module to access Prettier’s API, and your code can stay compatible with both Node and the browser as long as webpack or another bundler that supports the `browser` field is used. This is especially convenient for [plugins](plugins.md).
|
||||
|
||||
### `prettier.format(code, options)`
|
||||
|
||||
Unlike the `format` function from the [main API](api.md#prettierformatsource--options), this function does not load plugins automatically, so a `plugins` property is required if you want to load plugins. Additionally, the parsers included in the Prettier package won’t be loaded automatically, so you need to load them before using them.
|
||||
Unlike the `format` function from the [main API](api.md#prettierformatsource--options), this function does not load plugins automatically, so a `plugins` property is required if you want to load plugins. Additionally, the parsers included in the Prettier package won’t be loaded automatically, so you need to load them as plugins before using them.
|
||||
|
||||
See [Usage](#usage) below for examples.
|
||||
|
||||
|
||||
+7
-6
@@ -20,9 +20,9 @@
|
||||
"bin"
|
||||
],
|
||||
"dependencies": {
|
||||
"@angular/compiler": "10.2.1",
|
||||
"@angular/compiler": "10.2.2",
|
||||
"@babel/code-frame": "7.10.4",
|
||||
"@babel/parser": "7.12.3",
|
||||
"@babel/parser": "7.12.5",
|
||||
"@glimmer/syntax": "0.62.4",
|
||||
"@iarna/toml": "2.2.5",
|
||||
"@typescript-eslint/typescript-estree": "3.10.1",
|
||||
@@ -59,6 +59,7 @@
|
||||
"linguist-languages": "7.11.1",
|
||||
"lodash": "4.17.20",
|
||||
"mem": "8.0.0",
|
||||
"meriyah": "3.1.2",
|
||||
"minimatch": "3.0.4",
|
||||
"minimist": "1.2.5",
|
||||
"n-readlines": "1.0.0",
|
||||
@@ -86,7 +87,7 @@
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.12.3",
|
||||
"@babel/preset-env": "7.12.1",
|
||||
"@babel/types": "7.12.1",
|
||||
"@babel/types": "7.12.6",
|
||||
"@glimmer/reference": "0.62.4",
|
||||
"@rollup/plugin-alias": "3.1.1",
|
||||
"@rollup/plugin-babel": "5.2.1",
|
||||
@@ -97,7 +98,7 @@
|
||||
"@types/estree": "0.0.45",
|
||||
"@types/node": "14.14.0",
|
||||
"@typescript-eslint/types": "3.10.1",
|
||||
"babel-jest": "26.6.2",
|
||||
"babel-jest": "26.6.3",
|
||||
"babel-loader": "8.1.0",
|
||||
"benchmark": "2.1.4",
|
||||
"builtin-modules": "3.1.0",
|
||||
@@ -112,7 +113,7 @@
|
||||
"eslint-plugin-react": "7.21.5",
|
||||
"eslint-plugin-unicorn": "23.0.0",
|
||||
"execa": "4.1.0",
|
||||
"jest": "26.6.2",
|
||||
"jest": "26.6.3",
|
||||
"jest-snapshot-serializer-ansi": "1.0.0",
|
||||
"jest-snapshot-serializer-raw": "1.1.0",
|
||||
"jest-watch-typeahead": "0.6.1",
|
||||
@@ -129,7 +130,7 @@
|
||||
"synchronous-promise": "2.0.15",
|
||||
"tempy": "1.0.0",
|
||||
"terser-webpack-plugin": "5.0.3",
|
||||
"webpack": "5.3.2"
|
||||
"webpack": "5.4.0"
|
||||
},
|
||||
"scripts": {
|
||||
"prepublishOnly": "echo \"Error: must publish from dist/\" && exit 1",
|
||||
|
||||
@@ -45,6 +45,9 @@ const parsers = [
|
||||
{
|
||||
input: "src/language-js/parser-espree.js",
|
||||
},
|
||||
{
|
||||
input: "src/language-js/parser-meriyah.js",
|
||||
},
|
||||
{
|
||||
input: "src/language-js/parser-angular.js",
|
||||
},
|
||||
|
||||
@@ -18,7 +18,7 @@ module.exports = {
|
||||
},
|
||||
messages: {
|
||||
[MESSAGE_ID]:
|
||||
"Call `{{function}}` directly from `src/language-js/loc.js`.",
|
||||
"Please import `{{function}}` function and use it directly.",
|
||||
},
|
||||
fixable: "code",
|
||||
},
|
||||
|
||||
+12
-12
@@ -3,19 +3,17 @@
|
||||
const { isFrontMatterNode } = require("../common/util");
|
||||
const getLast = require("../utils/get-last");
|
||||
|
||||
function clean(ast, newObj, parent) {
|
||||
[
|
||||
"raw", // front-matter
|
||||
"raws",
|
||||
"sourceIndex",
|
||||
"source",
|
||||
"before",
|
||||
"after",
|
||||
"trailingComma",
|
||||
].forEach((name) => {
|
||||
delete newObj[name];
|
||||
});
|
||||
const ignoredProperties = new Set([
|
||||
"raw", // front-matter
|
||||
"raws",
|
||||
"sourceIndex",
|
||||
"source",
|
||||
"before",
|
||||
"after",
|
||||
"trailingComma",
|
||||
]);
|
||||
|
||||
function clean(ast, newObj, parent) {
|
||||
if (isFrontMatterNode(ast) && ast.lang === "yaml") {
|
||||
delete newObj.value;
|
||||
}
|
||||
@@ -170,6 +168,8 @@ function clean(ast, newObj, parent) {
|
||||
}
|
||||
}
|
||||
|
||||
clean.ignoredProperties = ignoredProperties;
|
||||
|
||||
function cleanCSSStrings(value) {
|
||||
return value.replace(/'/g, '"').replace(/\\([^\dA-Fa-f])/g, "$1");
|
||||
}
|
||||
|
||||
@@ -216,7 +216,17 @@ function replaceQuotesInInlineComments(text) {
|
||||
return text;
|
||||
}
|
||||
|
||||
function locStart(node) {
|
||||
return node.source.startOffset;
|
||||
}
|
||||
|
||||
function locEnd(node) {
|
||||
return node.source.endOffset;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
locStart,
|
||||
locEnd,
|
||||
calculateLoc,
|
||||
replaceQuotesInInlineComments,
|
||||
};
|
||||
@@ -12,6 +12,7 @@ const {
|
||||
isSCSSVariable,
|
||||
stringifyNode,
|
||||
} = require("./utils");
|
||||
const { locStart, locEnd } = require("./loc");
|
||||
const { calculateLoc, replaceQuotesInInlineComments } = require("./loc");
|
||||
|
||||
const getHighestAncestor = (node) => {
|
||||
@@ -605,6 +606,10 @@ function parseWithParser(parse, text, options) {
|
||||
calculateLoc(result, text);
|
||||
|
||||
if (frontMatter) {
|
||||
frontMatter.source = {
|
||||
startOffset: 0,
|
||||
endOffset: frontMatter.raw.length,
|
||||
};
|
||||
result.nodes.unshift(frontMatter);
|
||||
}
|
||||
|
||||
@@ -652,19 +657,8 @@ function parseScss(text, parsers, options) {
|
||||
const postCssParser = {
|
||||
astFormat: "postcss",
|
||||
hasPragma,
|
||||
locStart(node) {
|
||||
if (node.source) {
|
||||
return node.source.startOffset;
|
||||
}
|
||||
/* istanbul ignore next */
|
||||
return null;
|
||||
},
|
||||
locEnd(node) {
|
||||
if (node.source) {
|
||||
return node.source.endOffset;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
locStart,
|
||||
locEnd,
|
||||
};
|
||||
|
||||
// Export as a plugin so we can reuse the same bundle for UMD loading
|
||||
|
||||
@@ -74,6 +74,7 @@ const {
|
||||
lastLineHasInlineComment,
|
||||
isAtWordPlaceholderNode,
|
||||
} = require("./utils");
|
||||
const { locStart, locEnd } = require("./loc");
|
||||
|
||||
function shouldPrintComma(options) {
|
||||
return options.trailingComma === "es5" || options.trailingComma === "all";
|
||||
@@ -106,10 +107,8 @@ function genericPrint(path, options, print) {
|
||||
}
|
||||
case "css-comment": {
|
||||
const isInlineComment = node.inline || node.raws.inline;
|
||||
const text = options.originalText.slice(
|
||||
options.locStart(node),
|
||||
options.locEnd(node)
|
||||
);
|
||||
|
||||
const text = options.originalText.slice(locStart(node), locEnd(node));
|
||||
|
||||
return isInlineComment ? text.trimEnd() : text;
|
||||
}
|
||||
@@ -188,7 +187,7 @@ function genericPrint(path, options, print) {
|
||||
])
|
||||
: isTemplatePropNode(node) &&
|
||||
!parentNode.raws.semicolon &&
|
||||
options.originalText[options.locEnd(node) - 1] !== ";"
|
||||
options.originalText[locEnd(node) - 1] !== ";"
|
||||
? ""
|
||||
: options.__isHTMLStyleAttribute && isLastNode(path, node)
|
||||
? ifBreak(";", "")
|
||||
@@ -200,7 +199,7 @@ function genericPrint(path, options, print) {
|
||||
const isTemplatePlaceholderNodeWithoutSemiColon =
|
||||
isTemplatePlaceholderNode(node) &&
|
||||
!parentNode.raws.semicolon &&
|
||||
options.originalText[options.locEnd(node) - 1] !== ";";
|
||||
options.originalText[locEnd(node) - 1] !== ";";
|
||||
|
||||
if (isLessParser(options)) {
|
||||
if (node.mixin) {
|
||||
@@ -492,7 +491,7 @@ function genericPrint(path, options, print) {
|
||||
// originalText has to be used for Less, see replaceQuotesInInlineComments in loc.js
|
||||
const parentNode = path.getParentNode();
|
||||
if (parentNode.raws && parentNode.raws.selector) {
|
||||
const start = options.locStart(parentNode);
|
||||
const start = locStart(parentNode);
|
||||
const end = start + parentNode.raws.selector.length;
|
||||
return options.originalText.slice(start, end).trim();
|
||||
}
|
||||
@@ -505,8 +504,8 @@ function genericPrint(path, options, print) {
|
||||
grandParent.type === "value-func" &&
|
||||
grandParent.value === "selector"
|
||||
) {
|
||||
const start = options.locStart(parentNode.open) + 1;
|
||||
const end = options.locEnd(parentNode.close) - 1;
|
||||
const start = locStart(parentNode.open) + 1;
|
||||
const end = locEnd(parentNode.close) - 1;
|
||||
const selector = options.originalText.slice(start, end).trim();
|
||||
|
||||
return lastLineHasInlineComment(selector)
|
||||
@@ -522,10 +521,7 @@ function genericPrint(path, options, print) {
|
||||
return path.call(print, "group");
|
||||
}
|
||||
case "value-comment": {
|
||||
return options.originalText.slice(
|
||||
options.locStart(node),
|
||||
options.locEnd(node)
|
||||
);
|
||||
return options.originalText.slice(locStart(node), locEnd(node));
|
||||
}
|
||||
case "value-comma_group": {
|
||||
const parentNode = path.getParentNode();
|
||||
@@ -796,7 +792,7 @@ function genericPrint(path, options, print) {
|
||||
if (
|
||||
isAtWordPlaceholderNode(iNode) &&
|
||||
isAtWordPlaceholderNode(iNextNode) &&
|
||||
options.locEnd(iNode) === options.locStart(iNextNode)
|
||||
locEnd(iNode) === locStart(iNextNode)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
@@ -987,10 +983,7 @@ function printNodeSequence(path, options, print) {
|
||||
) {
|
||||
const childNode = pathChild.getValue();
|
||||
parts.push(
|
||||
options.originalText.slice(
|
||||
options.locStart(childNode),
|
||||
options.locEnd(childNode)
|
||||
)
|
||||
options.originalText.slice(locStart(childNode), locEnd(childNode))
|
||||
);
|
||||
} else {
|
||||
parts.push(pathChild.call(print));
|
||||
@@ -999,11 +992,9 @@ function printNodeSequence(path, options, print) {
|
||||
if (i !== node.nodes.length - 1) {
|
||||
if (
|
||||
(node.nodes[i + 1].type === "css-comment" &&
|
||||
!hasNewline(
|
||||
options.originalText,
|
||||
options.locStart(node.nodes[i + 1]),
|
||||
{ backwards: true }
|
||||
) &&
|
||||
!hasNewline(options.originalText, locStart(node.nodes[i + 1]), {
|
||||
backwards: true,
|
||||
}) &&
|
||||
!isFrontMatterNode(node.nodes[i])) ||
|
||||
(node.nodes[i + 1].type === "css-atrule" &&
|
||||
node.nodes[i + 1].name === "else" &&
|
||||
@@ -1013,11 +1004,7 @@ function printNodeSequence(path, options, print) {
|
||||
} else {
|
||||
parts.push(options.__isHTMLStyleAttribute ? line : hardline);
|
||||
if (
|
||||
isNextLineEmpty(
|
||||
options.originalText,
|
||||
pathChild.getValue(),
|
||||
options.locEnd
|
||||
) &&
|
||||
isNextLineEmpty(options.originalText, pathChild.getValue(), locEnd) &&
|
||||
!isFrontMatterNode(node.nodes[i])
|
||||
) {
|
||||
parts.push(hardline);
|
||||
|
||||
@@ -677,10 +677,8 @@ function printInterfaces(path, options, print) {
|
||||
return parts;
|
||||
}
|
||||
|
||||
function clean(node, newNode /*, parent*/) {
|
||||
delete newNode.loc;
|
||||
delete newNode.comments;
|
||||
}
|
||||
function clean(/*node, newNode , parent*/) {}
|
||||
clean.ignoredProperties = new Set(["loc", "comments"]);
|
||||
|
||||
module.exports = {
|
||||
print: genericPrint,
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = function (ast, newNode) {
|
||||
delete newNode.loc;
|
||||
delete newNode.selfClosing;
|
||||
|
||||
function clean(ast, newNode /*, parent*/) {
|
||||
// (Glimmer/HTML) ignore TextNode whitespace
|
||||
if (ast.type === "TextNode") {
|
||||
const trimmed = ast.chars.trim();
|
||||
@@ -12,4 +9,7 @@ module.exports = function (ast, newNode) {
|
||||
}
|
||||
newNode.chars = trimmed;
|
||||
}
|
||||
};
|
||||
}
|
||||
clean.ignoredProperties = new Set(["loc", "selfClosing"]);
|
||||
|
||||
module.exports = clean;
|
||||
@@ -18,8 +18,7 @@ const voidTags = new Set(htmlVoidElements);
|
||||
function isVoid(node) {
|
||||
return (
|
||||
(isGlimmerComponent(node) &&
|
||||
(node.children === 0 ||
|
||||
node.children.every((n) => isWhitespaceNode(n)))) ||
|
||||
node.children.every((n) => isWhitespaceNode(n))) ||
|
||||
voidTags.has(node.tag)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
|
||||
const { isFrontMatterNode } = require("../common/util");
|
||||
|
||||
module.exports = function (ast, newNode) {
|
||||
delete newNode.sourceSpan;
|
||||
delete newNode.startSourceSpan;
|
||||
delete newNode.endSourceSpan;
|
||||
delete newNode.nameSpan;
|
||||
delete newNode.valueSpan;
|
||||
const ignoredProperties = new Set([
|
||||
"sourceSpan",
|
||||
"startSourceSpan",
|
||||
"endSourceSpan",
|
||||
"nameSpan",
|
||||
"valueSpan",
|
||||
]);
|
||||
|
||||
function clean(ast, newNode) {
|
||||
if (ast.type === "text" || ast.type === "comment") {
|
||||
return null;
|
||||
}
|
||||
@@ -25,4 +27,8 @@ module.exports = function (ast, newNode) {
|
||||
if (ast.type === "docType") {
|
||||
delete newNode.value;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
clean.ignoredProperties = ignoredProperties;
|
||||
|
||||
module.exports = clean;
|
||||
@@ -1,5 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
const { isBlockComment } = require("./utils");
|
||||
|
||||
const ignoredProperties = new Set([
|
||||
"range",
|
||||
"raw",
|
||||
@@ -66,6 +68,7 @@ function clean(ast, newObj, parent) {
|
||||
ast.type === "MethodDefinition" ||
|
||||
ast.type === "ClassProperty" ||
|
||||
ast.type === "ClassMethod" ||
|
||||
ast.type === "FieldDefinition" ||
|
||||
ast.type === "TSDeclareMethod" ||
|
||||
ast.type === "TSPropertySignature" ||
|
||||
ast.type === "ObjectTypeProperty") &&
|
||||
@@ -183,7 +186,7 @@ function clean(ast, newObj, parent) {
|
||||
ast.leadingComments &&
|
||||
ast.leadingComments.some(
|
||||
(comment) =>
|
||||
comment.type === "CommentBlock" &&
|
||||
isBlockComment(comment) &&
|
||||
["GraphQL", "HTML"].some(
|
||||
(languageName) => comment.value === ` ${languageName} `
|
||||
)
|
||||
|
||||
@@ -492,6 +492,7 @@ function handleMethodNameComments(text, enclosingNode, precedingNode, comment) {
|
||||
precedingNode.type === "Decorator" &&
|
||||
(enclosingNode.type === "ClassMethod" ||
|
||||
enclosingNode.type === "ClassProperty" ||
|
||||
enclosingNode.type === "FieldDefinition" ||
|
||||
enclosingNode.type === "TSAbstractClassProperty" ||
|
||||
enclosingNode.type === "TSAbstractMethodDefinition" ||
|
||||
enclosingNode.type === "TSDeclareMethod" ||
|
||||
@@ -934,7 +935,8 @@ function getCommentChildNodes(node, options) {
|
||||
if (
|
||||
(options.parser === "typescript" ||
|
||||
options.parser === "flow" ||
|
||||
options.parser === "espree") &&
|
||||
options.parser === "espree" ||
|
||||
options.parser === "meriyah") &&
|
||||
node.type === "MethodDefinition" &&
|
||||
node.value &&
|
||||
node.value.type === "FunctionExpression" &&
|
||||
@@ -963,7 +965,6 @@ module.exports = {
|
||||
handleEndOfLineComment,
|
||||
handleRemainingComment,
|
||||
hasLeadingComment,
|
||||
isBlockComment,
|
||||
isTypeCastComment,
|
||||
getGapRegex,
|
||||
getCommentChildNodes,
|
||||
|
||||
@@ -15,7 +15,8 @@ const {
|
||||
},
|
||||
utils: { mapDoc, replaceNewlinesWithLiterallines },
|
||||
} = require("../document");
|
||||
const { isBlockComment, hasLeadingComment } = require("./comments");
|
||||
const { isBlockComment } = require("./utils");
|
||||
const { hasLeadingComment } = require("./comments");
|
||||
|
||||
function getParser(path) {
|
||||
if (
|
||||
|
||||
@@ -13,6 +13,7 @@ const languages = [
|
||||
parsers: [
|
||||
"babel",
|
||||
"espree",
|
||||
"meriyah",
|
||||
"babel-flow",
|
||||
"babel-ts",
|
||||
"flow",
|
||||
@@ -45,6 +46,7 @@ const languages = [
|
||||
"flow",
|
||||
"typescript",
|
||||
"espree",
|
||||
"meriyah",
|
||||
],
|
||||
vscodeLanguageIds: ["javascriptreact"],
|
||||
})),
|
||||
@@ -151,6 +153,10 @@ const parsers = {
|
||||
get espree() {
|
||||
return require("./parser-espree").parsers.espree;
|
||||
},
|
||||
// JS - meriyah
|
||||
get meriyah() {
|
||||
return require("./parser-meriyah").parsers.meriyah;
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* @typedef {import("./types/estree").Node} Node
|
||||
*/
|
||||
|
||||
function locStart(node, opts) {
|
||||
const { ignoreDecorators } = opts || {};
|
||||
|
||||
@@ -21,6 +25,11 @@ function locEnd(node) {
|
||||
return node.typeAnnotation ? Math.max(end, locEnd(node.typeAnnotation)) : end;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} startNode
|
||||
* @param {Node | number} endNodeOrLength
|
||||
* @returns {number[]}
|
||||
*/
|
||||
function composeLoc(startNode, endNodeOrLength = startNode) {
|
||||
const start = locStart(startNode);
|
||||
const end =
|
||||
@@ -31,8 +40,37 @@ function composeLoc(startNode, endNodeOrLength = startNode) {
|
||||
return [start, end];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} nodeA
|
||||
* @param {Node} nodeB
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function hasSameLocStart(nodeA, nodeB) {
|
||||
return locStart(nodeA) === locStart(nodeB);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} nodeA
|
||||
* @param {Node} nodeB
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function hasSameLocEnd(nodeA, nodeB) {
|
||||
return locEnd(nodeA) === locEnd(nodeB);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} nodeA
|
||||
* @param {Node} nodeB
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function hasSameLoc(nodeA, nodeB) {
|
||||
return hasSameLocStart(nodeA, nodeB) && hasSameLocEnd(nodeA, nodeB);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
locStart,
|
||||
locEnd,
|
||||
composeLoc,
|
||||
hasSameLocStart,
|
||||
hasSameLoc,
|
||||
};
|
||||
@@ -494,7 +494,8 @@ function needsParens(path, options) {
|
||||
return true;
|
||||
} else if (
|
||||
name === "key" &&
|
||||
parent.type === "ClassProperty" &&
|
||||
(parent.type === "ClassProperty" ||
|
||||
parent.type === "FieldDefinition") &&
|
||||
parent.computed
|
||||
) {
|
||||
return false;
|
||||
@@ -745,6 +746,7 @@ function isStatement(node) {
|
||||
node.type === "ClassDeclaration" ||
|
||||
node.type === "ClassMethod" ||
|
||||
node.type === "ClassProperty" ||
|
||||
node.type === "FieldDefinition" ||
|
||||
node.type === "ClassPrivateProperty" ||
|
||||
node.type === "ContinueStatement" ||
|
||||
node.type === "DebuggerStatement" ||
|
||||
|
||||
@@ -35,17 +35,16 @@ function parse(originalText, parsers, options) {
|
||||
} catch (moduleError) {
|
||||
try {
|
||||
ast = parse(text, { ...espreeOptions, sourceType: "script" });
|
||||
} catch (scriptError) {
|
||||
} catch (_) {
|
||||
// throw the error for `module` parsing
|
||||
const { message, lineNumber, column } = moduleError;
|
||||
|
||||
/* istanbul ignore next */
|
||||
if (typeof moduleError.lineNumber !== "number") {
|
||||
if (typeof lineNumber !== "number") {
|
||||
throw moduleError;
|
||||
}
|
||||
|
||||
throw createError(moduleError.message, {
|
||||
start: { line: moduleError.lineNumber, column: moduleError.column },
|
||||
});
|
||||
throw createError(message, { start: { line: lineNumber, column } });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
"use strict";
|
||||
|
||||
const createError = require("../common/parser-create-error");
|
||||
const { hasPragma } = require("./pragma");
|
||||
const { locStart, locEnd } = require("./loc");
|
||||
const postprocess = require("./postprocess");
|
||||
|
||||
// https://github.com/meriyah/meriyah/blob/4676f60b6c149d7082bde2c9147f9ae2359c8075/src/parser.ts#L185
|
||||
const parseOptions = {
|
||||
// Allow module code
|
||||
module: true,
|
||||
// Enable stage 3 support (ESNext)
|
||||
next: true,
|
||||
// Enable start and end offsets to each node
|
||||
ranges: true,
|
||||
// Enable web compatibility
|
||||
webcompat: true,
|
||||
// Enable line/column location information to each node
|
||||
loc: true,
|
||||
// Attach raw property to each literal and identifier node
|
||||
raw: true,
|
||||
// Enabled directives
|
||||
directives: true,
|
||||
// Allow return in the global scope
|
||||
globalReturn: true,
|
||||
// Enable implied strict mode
|
||||
impliedStrict: false,
|
||||
// Enable non-standard parenthesized expression node
|
||||
preserveParens: false,
|
||||
// Enable lexical binding and scope tracking
|
||||
lexical: false,
|
||||
// Adds a source attribute in every node’s loc object when the locations option is `true`
|
||||
// source: '',
|
||||
// Distinguish Identifier from IdentifierPattern
|
||||
identifierPattern: false,
|
||||
// Enable React JSX parsing
|
||||
jsx: true,
|
||||
// Allow edge cases that deviate from the spec
|
||||
specDeviation: true,
|
||||
// Creates unique key for in ObjectPattern when key value are same
|
||||
uniqueKeyInPattern: false,
|
||||
};
|
||||
|
||||
function parseWithOptions(text, module) {
|
||||
const { parse } = require("meriyah");
|
||||
const comments = [];
|
||||
const tokens = [];
|
||||
const ast = parse(text, {
|
||||
...parseOptions,
|
||||
module,
|
||||
onComment: comments,
|
||||
onToken: tokens,
|
||||
});
|
||||
ast.comments = comments;
|
||||
ast.tokens = tokens;
|
||||
|
||||
return ast;
|
||||
}
|
||||
|
||||
function parse(text, parsers, options) {
|
||||
let ast;
|
||||
|
||||
try {
|
||||
ast = parseWithOptions(text /* module */, true);
|
||||
} catch (moduleError) {
|
||||
try {
|
||||
ast = parseWithOptions(text, /* module */ false);
|
||||
} catch (_) {
|
||||
// throw the error for `module` parsing
|
||||
const { message, line, column } = moduleError;
|
||||
|
||||
/* istanbul ignore next */
|
||||
if (typeof line !== "number") {
|
||||
throw moduleError;
|
||||
}
|
||||
|
||||
throw createError(message, { start: { line, column } });
|
||||
}
|
||||
}
|
||||
|
||||
return postprocess(ast, { ...options, originalText: text });
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
parsers: {
|
||||
meriyah: { parse, astFormat: "estree", hasPragma, locStart, locEnd },
|
||||
},
|
||||
};
|
||||
@@ -21,7 +21,8 @@ function postprocess(ast, options) {
|
||||
if (
|
||||
options.parser !== "typescript" &&
|
||||
options.parser !== "flow" &&
|
||||
options.parser !== "espree"
|
||||
options.parser !== "espree" &&
|
||||
options.parser !== "meriyah"
|
||||
) {
|
||||
const startOffsetsOfTypeCastedNodes = new Set();
|
||||
|
||||
|
||||
@@ -0,0 +1,197 @@
|
||||
"use strict";
|
||||
|
||||
const {
|
||||
getNextNonSpaceNonCommentCharacter,
|
||||
isNextLineEmpty,
|
||||
} = require("../../common/util");
|
||||
const { printDanglingComments } = require("../../main/comments");
|
||||
const {
|
||||
builders: { concat, line, hardline, softline, group, indent, ifBreak },
|
||||
utils: { removeLines },
|
||||
} = require("../../document");
|
||||
const {
|
||||
getFunctionParameters,
|
||||
iterateFunctionParametersPath,
|
||||
isSimpleType,
|
||||
isTestCall,
|
||||
isTypeAnnotationAFunction,
|
||||
isObjectType,
|
||||
isObjectTypePropertyAFunction,
|
||||
hasRestParameter,
|
||||
shouldPrintComma,
|
||||
} = require("../utils");
|
||||
const { locEnd } = require("../loc");
|
||||
const { printFunctionTypeParameters } = require("./misc");
|
||||
|
||||
function printFunctionParameters(
|
||||
path,
|
||||
print,
|
||||
options,
|
||||
expandArg,
|
||||
printTypeParams
|
||||
) {
|
||||
const functionNode = path.getValue();
|
||||
const parameters = getFunctionParameters(functionNode);
|
||||
const typeParams = printTypeParams
|
||||
? printFunctionTypeParameters(path, options, print)
|
||||
: "";
|
||||
|
||||
if (parameters.length === 0) {
|
||||
return concat([
|
||||
typeParams,
|
||||
"(",
|
||||
printDanglingComments(
|
||||
path,
|
||||
options,
|
||||
/* sameIndent */ true,
|
||||
(comment) =>
|
||||
getNextNonSpaceNonCommentCharacter(
|
||||
options.originalText,
|
||||
comment,
|
||||
locEnd
|
||||
) === ")"
|
||||
),
|
||||
")",
|
||||
]);
|
||||
}
|
||||
|
||||
const parent = path.getParentNode();
|
||||
const isParametersInTestCall = isTestCall(parent);
|
||||
const shouldHugParameters = shouldHugFunctionParameters(functionNode);
|
||||
const shouldExpandParameters =
|
||||
expandArg && !parameters.some((node) => node.comments);
|
||||
const printed = [];
|
||||
iterateFunctionParametersPath(path, (parameterPath, index) => {
|
||||
const isLastParameter = index === parameters.length - 1;
|
||||
if (isLastParameter && functionNode.rest) {
|
||||
printed.push("...");
|
||||
}
|
||||
printed.push(parameterPath.call(print));
|
||||
if (isLastParameter) {
|
||||
return;
|
||||
}
|
||||
printed.push(",");
|
||||
if (
|
||||
isParametersInTestCall ||
|
||||
shouldHugParameters ||
|
||||
shouldExpandParameters
|
||||
) {
|
||||
printed.push(" ");
|
||||
} else if (
|
||||
isNextLineEmpty(options.originalText, parameters[index], locEnd)
|
||||
) {
|
||||
printed.push(hardline, hardline);
|
||||
} else {
|
||||
printed.push(line);
|
||||
}
|
||||
});
|
||||
|
||||
// If the parent is a call with the first/last argument expansion and this is the
|
||||
// params of the first/last argument, we don't want the arguments to break and instead
|
||||
// want the whole expression to be on a new line.
|
||||
//
|
||||
// Good: Bad:
|
||||
// verylongcall( verylongcall((
|
||||
// (a, b) => { a,
|
||||
// } b,
|
||||
// }) ) => {
|
||||
// })
|
||||
if (shouldExpandParameters) {
|
||||
return group(
|
||||
concat([
|
||||
removeLines(typeParams),
|
||||
"(",
|
||||
concat(printed.map(removeLines)),
|
||||
")",
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
// Single object destructuring should hug
|
||||
//
|
||||
// function({
|
||||
// a,
|
||||
// b,
|
||||
// c
|
||||
// }) {}
|
||||
const hasNotParameterDecorator = parameters.every((node) => !node.decorators);
|
||||
if (shouldHugParameters && hasNotParameterDecorator) {
|
||||
return concat([typeParams, "(", concat(printed), ")"]);
|
||||
}
|
||||
|
||||
// don't break in specs, eg; `it("should maintain parens around done even when long", (done) => {})`
|
||||
if (isParametersInTestCall) {
|
||||
return concat([typeParams, "(", concat(printed), ")"]);
|
||||
}
|
||||
|
||||
const isFlowShorthandWithOneArg =
|
||||
(isObjectTypePropertyAFunction(parent) ||
|
||||
isTypeAnnotationAFunction(parent) ||
|
||||
parent.type === "TypeAlias" ||
|
||||
parent.type === "UnionTypeAnnotation" ||
|
||||
parent.type === "TSUnionType" ||
|
||||
parent.type === "IntersectionTypeAnnotation" ||
|
||||
(parent.type === "FunctionTypeAnnotation" &&
|
||||
parent.returnType === functionNode)) &&
|
||||
parameters.length === 1 &&
|
||||
parameters[0].name === null &&
|
||||
// `type q = (this: string) => void;`
|
||||
functionNode.this !== parameters[0] &&
|
||||
parameters[0].typeAnnotation &&
|
||||
functionNode.typeParameters === null &&
|
||||
isSimpleType(parameters[0].typeAnnotation) &&
|
||||
!functionNode.rest;
|
||||
|
||||
if (isFlowShorthandWithOneArg) {
|
||||
if (options.arrowParens === "always") {
|
||||
return concat(["(", concat(printed), ")"]);
|
||||
}
|
||||
return concat(printed);
|
||||
}
|
||||
|
||||
return concat([
|
||||
typeParams,
|
||||
"(",
|
||||
indent(concat([softline, concat(printed)])),
|
||||
ifBreak(
|
||||
!hasRestParameter(functionNode) && shouldPrintComma(options, "all")
|
||||
? ","
|
||||
: ""
|
||||
),
|
||||
softline,
|
||||
")",
|
||||
]);
|
||||
}
|
||||
|
||||
function shouldHugFunctionParameters(node) {
|
||||
if (!node) {
|
||||
return false;
|
||||
}
|
||||
const parameters = getFunctionParameters(node);
|
||||
if (parameters.length !== 1) {
|
||||
return false;
|
||||
}
|
||||
const [parameter] = parameters;
|
||||
return (
|
||||
!parameter.comments &&
|
||||
(parameter.type === "ObjectPattern" ||
|
||||
parameter.type === "ArrayPattern" ||
|
||||
(parameter.type === "Identifier" &&
|
||||
parameter.typeAnnotation &&
|
||||
(parameter.typeAnnotation.type === "TypeAnnotation" ||
|
||||
parameter.typeAnnotation.type === "TSTypeAnnotation") &&
|
||||
isObjectType(parameter.typeAnnotation.typeAnnotation)) ||
|
||||
(parameter.type === "FunctionTypeParam" &&
|
||||
isObjectType(parameter.typeAnnotation)) ||
|
||||
(parameter.type === "AssignmentPattern" &&
|
||||
(parameter.left.type === "ObjectPattern" ||
|
||||
parameter.left.type === "ArrayPattern") &&
|
||||
(parameter.right.type === "Identifier" ||
|
||||
(parameter.right.type === "ObjectExpression" &&
|
||||
parameter.right.properties.length === 0) ||
|
||||
(parameter.right.type === "ArrayExpression" &&
|
||||
parameter.right.elements.length === 0))))
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = { printFunctionParameters, shouldHugFunctionParameters };
|
||||
@@ -94,7 +94,22 @@ function printModuleSpecifiers(path, options, print) {
|
||||
return concat(parts);
|
||||
}
|
||||
|
||||
function printImportAssertions(path, options, print) {
|
||||
const node = path.getNode();
|
||||
if (Array.isArray(node.assertions) && node.assertions.length !== 0) {
|
||||
return concat([
|
||||
" assert {",
|
||||
options.bracketSpacing ? " " : "",
|
||||
join(", ", path.map(print, "assertions")),
|
||||
options.bracketSpacing ? " " : "",
|
||||
"}",
|
||||
]);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
printModuleSource,
|
||||
printModuleSpecifiers,
|
||||
printImportAssertions,
|
||||
};
|
||||
@@ -1,11 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
const flat = require("lodash/flatten");
|
||||
|
||||
const { isJSXNode } = require("../utils");
|
||||
const { locStart, locEnd } = require("../loc");
|
||||
const { hasNewlineInRange } = require("../../common/util");
|
||||
const handleComments = require("../comments");
|
||||
const { isJSXNode, isBlockComment } = require("../utils");
|
||||
const { locStart, locEnd } = require("../loc");
|
||||
const {
|
||||
builders: {
|
||||
concat,
|
||||
@@ -259,7 +257,7 @@ function printTernaryOperator(path, options, print, operatorOptions) {
|
||||
]).filter(Boolean);
|
||||
const shouldBreak = comments.some(
|
||||
(comment) =>
|
||||
handleComments.isBlockComment(comment) &&
|
||||
isBlockComment(comment) &&
|
||||
hasNewlineInRange(
|
||||
options.originalText,
|
||||
locStart(comment),
|
||||
|
||||
@@ -58,23 +58,28 @@ function genericPrint(path, options, print) {
|
||||
}
|
||||
}
|
||||
|
||||
function clean(node, newNode /*, parent*/) {
|
||||
delete newNode.start;
|
||||
delete newNode.end;
|
||||
delete newNode.extra;
|
||||
delete newNode.loc;
|
||||
delete newNode.comments;
|
||||
delete newNode.errors;
|
||||
delete newNode.range;
|
||||
const ignoredProperties = new Set([
|
||||
"start",
|
||||
"end",
|
||||
"extra",
|
||||
"loc",
|
||||
"comments",
|
||||
"errors",
|
||||
"range",
|
||||
]);
|
||||
|
||||
if (node.type === "Identifier") {
|
||||
function clean(node, newNode /*, parent*/) {
|
||||
const { type } = node;
|
||||
if (type === "Identifier") {
|
||||
return { type: "StringLiteral", value: node.name };
|
||||
}
|
||||
if (node.type === "UnaryExpression" && node.operator === "+") {
|
||||
if (type === "UnaryExpression" && node.operator === "+") {
|
||||
return newNode.argument;
|
||||
}
|
||||
}
|
||||
|
||||
clean.ignoredProperties = ignoredProperties;
|
||||
|
||||
module.exports = {
|
||||
preprocess,
|
||||
print: genericPrint,
|
||||
|
||||
+109
-278
@@ -8,7 +8,6 @@ const assert = require("assert");
|
||||
// TODO(azz): anything that imports from main shouldn't be in a `language-*` dir.
|
||||
const comments = require("../main/comments");
|
||||
const {
|
||||
getNextNonSpaceNonCommentCharacter,
|
||||
hasNewline,
|
||||
hasNewlineInRange,
|
||||
getLast,
|
||||
@@ -19,11 +18,9 @@ const {
|
||||
hasNodeIgnoreComment,
|
||||
getIndentSize,
|
||||
getPreferredQuote,
|
||||
} = require("../common/util");
|
||||
const {
|
||||
isNextLineEmpty,
|
||||
getNextNonSpaceNonCommentCharacterIndex,
|
||||
} = require("../common/util-shared");
|
||||
} = require("../common/util");
|
||||
const {
|
||||
builders: {
|
||||
concat,
|
||||
@@ -41,7 +38,7 @@ const {
|
||||
lineSuffixBoundary,
|
||||
addAlignmentToDoc,
|
||||
},
|
||||
utils: { willBreak, isLineNext, isEmpty, removeLines, normalizeParts },
|
||||
utils: { willBreak, isLineNext, isEmpty, normalizeParts },
|
||||
printer: { printDocToString },
|
||||
} = require("../document");
|
||||
const embed = require("./embed");
|
||||
@@ -57,10 +54,7 @@ const preprocess = require("./preprocess");
|
||||
const {
|
||||
classChildNeedsASIProtection,
|
||||
classPropMayCauseASIProblems,
|
||||
getFlowVariance,
|
||||
getFunctionParameters,
|
||||
iterateFunctionParametersPath,
|
||||
hasRestParameter,
|
||||
getLeftSidePathName,
|
||||
getParentExportDeclaration,
|
||||
getTypeScriptMappedTypeModifier,
|
||||
@@ -72,7 +66,6 @@ const {
|
||||
hasNewlineBetweenOrAfterDecorators,
|
||||
hasNgSideEffect,
|
||||
hasPrettierIgnore,
|
||||
hasSameLoc,
|
||||
hasTrailingComment,
|
||||
hasTrailingLineComment,
|
||||
identity,
|
||||
@@ -104,7 +97,8 @@ const {
|
||||
isTestCall,
|
||||
isTheOnlyJSXElementInMarkdown,
|
||||
isTSXFile,
|
||||
isTypeAnnotationAFunction,
|
||||
isBlockComment,
|
||||
isLineComment,
|
||||
matchJsxWhitespaceRegex,
|
||||
needsHardlineAfterDanglingComment,
|
||||
rawText,
|
||||
@@ -113,7 +107,7 @@ const {
|
||||
shouldFlatten,
|
||||
startsWithNoLookaheadToken,
|
||||
} = require("./utils");
|
||||
const { locStart, locEnd } = require("./loc");
|
||||
const { locStart, locEnd, hasSameLoc } = require("./loc");
|
||||
|
||||
const printMemberChain = require("./print/member-chain");
|
||||
const printCallArguments = require("./print/call-arguments");
|
||||
@@ -123,8 +117,16 @@ const {
|
||||
printMemberLookup,
|
||||
printBindExpressionCallee,
|
||||
} = require("./print/misc");
|
||||
const { printModuleSource, printModuleSpecifiers } = require("./print/module");
|
||||
const {
|
||||
printModuleSource,
|
||||
printModuleSpecifiers,
|
||||
printImportAssertions,
|
||||
} = require("./print/module");
|
||||
const printTernaryOperator = require("./print/ternary");
|
||||
const {
|
||||
printFunctionParameters,
|
||||
shouldHugFunctionParameters,
|
||||
} = require("./print/function-parameters");
|
||||
|
||||
const needsQuoteProps = new WeakMap();
|
||||
|
||||
@@ -145,6 +147,7 @@ function genericPrint(path, options, printPath, args) {
|
||||
node.type === "ClassMethod" ||
|
||||
node.type === "ClassPrivateMethod" ||
|
||||
node.type === "ClassProperty" ||
|
||||
node.type === "FieldDefinition" ||
|
||||
node.type === "TSAbstractClassProperty" ||
|
||||
node.type === "ClassPrivateProperty" ||
|
||||
node.type === "MethodDefinition" ||
|
||||
@@ -457,6 +460,7 @@ function printPathNoParens(path, options, print, args) {
|
||||
parent.type === "AssignmentExpression" ||
|
||||
parent.type === "VariableDeclarator" ||
|
||||
parent.type === "ClassProperty" ||
|
||||
parent.type === "FieldDefinition" ||
|
||||
parent.type === "TSAbstractClassProperty" ||
|
||||
parent.type === "ClassPrivateProperty" ||
|
||||
parent.type === "ObjectProperty" ||
|
||||
@@ -804,7 +808,7 @@ function printPathNoParens(path, options, print, args) {
|
||||
|
||||
parts.push(path.call(print, "imported"));
|
||||
|
||||
if (n.local && !hasSameLoc(n.local, n.imported, options)) {
|
||||
if (n.local && !hasSameLoc(n.local, n.imported)) {
|
||||
parts.push(" as ", path.call(print, "local"));
|
||||
}
|
||||
|
||||
@@ -812,7 +816,7 @@ function printPathNoParens(path, options, print, args) {
|
||||
case "ExportSpecifier": {
|
||||
parts.push(path.call(print, "local"));
|
||||
|
||||
if (n.exported && !hasSameLoc(n.local, n.exported, options)) {
|
||||
if (n.exported && !hasSameLoc(n.local, n.exported)) {
|
||||
parts.push(" as ", path.call(print, "exported"));
|
||||
}
|
||||
|
||||
@@ -844,7 +848,11 @@ function printPathNoParens(path, options, print, args) {
|
||||
parts.push(" as ", path.call(print, "exported"));
|
||||
}
|
||||
|
||||
parts.push(printModuleSource(path, options, print), semi);
|
||||
parts.push(
|
||||
printModuleSource(path, options, print),
|
||||
printImportAssertions(path, options, print),
|
||||
semi
|
||||
);
|
||||
|
||||
return concat(parts);
|
||||
|
||||
@@ -874,13 +882,7 @@ function printPathNoParens(path, options, print, args) {
|
||||
parts.push(" ", path.call(print, "source"));
|
||||
}
|
||||
|
||||
if (Array.isArray(n.assertions) && n.assertions.length !== 0) {
|
||||
parts.push(
|
||||
" assert { ",
|
||||
join(", ", path.map(print, "assertions")),
|
||||
" }"
|
||||
);
|
||||
}
|
||||
parts.push(printImportAssertions(path, options, print));
|
||||
|
||||
parts.push(semi);
|
||||
|
||||
@@ -1002,6 +1004,7 @@ function printPathNoParens(path, options, print, args) {
|
||||
//
|
||||
// Here, we ensure that such comments stay between the Identifier and the Callee.
|
||||
const isIdentifierWithFlowAnnotation =
|
||||
(options.parser === "babel" || options.parser === "babel-flow") &&
|
||||
n.callee &&
|
||||
n.callee.type === "Identifier" &&
|
||||
hasFlowAnnotationComment(n.callee.trailingComments);
|
||||
@@ -1159,8 +1162,8 @@ function printPathNoParens(path, options, print, args) {
|
||||
if (n.inexact) {
|
||||
let printed;
|
||||
if (hasDanglingComments(n)) {
|
||||
const hasLineComments = !n.comments.every(
|
||||
handleComments.isBlockComment
|
||||
const hasLineComments = !n.comments.every((comment) =>
|
||||
isBlockComment(comment)
|
||||
);
|
||||
const printedDanglingComments = comments.printDanglingComments(
|
||||
path,
|
||||
@@ -1242,7 +1245,7 @@ function printPathNoParens(path, options, print, args) {
|
||||
path.match(
|
||||
(node) => node.type === "ObjectPattern" && !node.decorators,
|
||||
(node, name, number) =>
|
||||
shouldHugArguments(node) &&
|
||||
shouldHugFunctionParameters(node) &&
|
||||
(name === "params" ||
|
||||
name === "parameters" ||
|
||||
name === "this" ||
|
||||
@@ -1254,7 +1257,7 @@ function printPathNoParens(path, options, print, args) {
|
||||
(node, name) => name === "typeAnnotation",
|
||||
(node, name) => name === "typeAnnotation",
|
||||
(node, name, number) =>
|
||||
shouldHugArguments(node) &&
|
||||
shouldHugFunctionParameters(node) &&
|
||||
(name === "params" ||
|
||||
name === "parameters" ||
|
||||
name === "this" ||
|
||||
@@ -1627,8 +1630,7 @@ function printPathNoParens(path, options, print, args) {
|
||||
const commentOnOwnLine =
|
||||
(hasTrailingComment(n.consequent) &&
|
||||
n.consequent.comments.some(
|
||||
(comment) =>
|
||||
comment.trailing && !handleComments.isBlockComment(comment)
|
||||
(comment) => comment.trailing && !isBlockComment(comment)
|
||||
)) ||
|
||||
needsHardlineAfterDanglingComment(n);
|
||||
const elseOnSameLine =
|
||||
@@ -1811,7 +1813,7 @@ function printPathNoParens(path, options, print, args) {
|
||||
n.param.comments &&
|
||||
n.param.comments.some(
|
||||
(comment) =>
|
||||
!handleComments.isBlockComment(comment) ||
|
||||
!isBlockComment(comment) ||
|
||||
(comment.leading &&
|
||||
hasNewline(options.originalText, locEnd(comment))) ||
|
||||
(comment.trailing &&
|
||||
@@ -2112,7 +2114,7 @@ function printPathNoParens(path, options, print, args) {
|
||||
case "JSXClosingFragment": {
|
||||
const hasComment = n.comments && n.comments.length;
|
||||
const hasOwnLineComment =
|
||||
hasComment && !n.comments.every(handleComments.isBlockComment);
|
||||
hasComment && !n.comments.every((comment) => isBlockComment(comment));
|
||||
const isOpeningFragment = n.type === "JSXOpeningFragment";
|
||||
return concat([
|
||||
isOpeningFragment ? "<" : "</",
|
||||
@@ -2135,7 +2137,7 @@ function printPathNoParens(path, options, print, args) {
|
||||
throw new Error("JSXTest should be handled by JSXElement");
|
||||
case "JSXEmptyExpression": {
|
||||
const requiresHardline =
|
||||
n.comments && !n.comments.every(handleComments.isBlockComment);
|
||||
n.comments && !n.comments.every((comment) => isBlockComment(comment));
|
||||
|
||||
return concat([
|
||||
comments.printDanglingComments(
|
||||
@@ -2167,6 +2169,7 @@ function printPathNoParens(path, options, print, args) {
|
||||
"}",
|
||||
]);
|
||||
case "ClassProperty":
|
||||
case "FieldDefinition":
|
||||
case "TSAbstractClassProperty":
|
||||
case "ClassPrivateProperty": {
|
||||
if (n.decorators && n.decorators.length !== 0) {
|
||||
@@ -2187,9 +2190,8 @@ function printPathNoParens(path, options, print, args) {
|
||||
if (n.readonly) {
|
||||
parts.push("readonly ");
|
||||
}
|
||||
const variance = getFlowVariance(n);
|
||||
if (variance) {
|
||||
parts.push(variance);
|
||||
if (n.variance) {
|
||||
parts.push(path.call(print, "variance"));
|
||||
}
|
||||
parts.push(
|
||||
printPropertyKey(path, options, print),
|
||||
@@ -2539,7 +2541,7 @@ function printPathNoParens(path, options, print, args) {
|
||||
!(
|
||||
((parent.type === "ObjectTypeProperty" ||
|
||||
parent.type === "ObjectTypeInternalSlot") &&
|
||||
!getFlowVariance(parent) &&
|
||||
!parent.variance &&
|
||||
!parent.optional &&
|
||||
locStart(parent) === locStart(n)) ||
|
||||
parent.type === "ObjectTypeCallProperty" ||
|
||||
@@ -2561,7 +2563,7 @@ function printPathNoParens(path, options, print, args) {
|
||||
parent.type === "TSTypeAnnotation") &&
|
||||
parentParent.type === "ArrowFunctionExpression";
|
||||
|
||||
if (isObjectTypePropertyAFunction(parent, options)) {
|
||||
if (isObjectTypePropertyAFunction(parent)) {
|
||||
isArrowFunctionTypeAnnotation = true;
|
||||
needsColon = true;
|
||||
}
|
||||
@@ -2806,6 +2808,11 @@ function printPathNoParens(path, options, print, args) {
|
||||
}
|
||||
case "NullableTypeAnnotation":
|
||||
return concat(["?", path.call(print, "typeAnnotation")]);
|
||||
case "Variance": {
|
||||
const { kind } = n;
|
||||
assert.ok(kind === "plus" || kind === "minus");
|
||||
return kind === "plus" ? "+" : "-";
|
||||
}
|
||||
case "ObjectTypeCallProperty":
|
||||
if (n.static) {
|
||||
parts.push("static ");
|
||||
@@ -2815,9 +2822,8 @@ function printPathNoParens(path, options, print, args) {
|
||||
|
||||
return concat(parts);
|
||||
case "ObjectTypeIndexer": {
|
||||
const variance = getFlowVariance(n);
|
||||
return concat([
|
||||
variance || "",
|
||||
n.variance ? path.call(print, "variance") : "",
|
||||
"[",
|
||||
path.call(print, "id"),
|
||||
n.id ? ": " : "",
|
||||
@@ -2827,8 +2833,6 @@ function printPathNoParens(path, options, print, args) {
|
||||
]);
|
||||
}
|
||||
case "ObjectTypeProperty": {
|
||||
const variance = getFlowVariance(n);
|
||||
|
||||
let modifier = "";
|
||||
|
||||
if (n.proto) {
|
||||
@@ -2840,10 +2844,10 @@ function printPathNoParens(path, options, print, args) {
|
||||
return concat([
|
||||
modifier,
|
||||
isGetterOrSetter(n) ? n.kind + " " : "",
|
||||
variance || "",
|
||||
n.variance ? path.call(print, "variance") : "",
|
||||
printPropertyKey(path, options, print),
|
||||
printOptionalToken(path),
|
||||
isFunctionNotation(n, options) ? "" : ": ",
|
||||
isFunctionNotation(n) ? "" : ": ",
|
||||
path.call(print, "value"),
|
||||
]);
|
||||
}
|
||||
@@ -2899,28 +2903,28 @@ function printPathNoParens(path, options, print, args) {
|
||||
|
||||
case "TypeParameterDeclaration":
|
||||
case "TypeParameterInstantiation": {
|
||||
const start = locStart(n);
|
||||
const end = locEnd(n);
|
||||
const commentStartIndex = options.originalText.lastIndexOf("/*", start);
|
||||
const commentEndIndex = options.originalText.indexOf("*/", end);
|
||||
if (commentStartIndex !== -1 && commentEndIndex !== -1) {
|
||||
const comment = options.originalText
|
||||
.slice(commentStartIndex + 2, commentEndIndex)
|
||||
.trim();
|
||||
if (
|
||||
comment.startsWith("::") &&
|
||||
!comment.includes("/*") &&
|
||||
!comment.includes("*/")
|
||||
) {
|
||||
return concat([
|
||||
"/*:: ",
|
||||
printTypeParameters(path, options, print, "params"),
|
||||
" */",
|
||||
]);
|
||||
const printed = printTypeParameters(path, options, print, "params");
|
||||
|
||||
if (options.parser === "flow") {
|
||||
const start = locStart(n);
|
||||
const end = locEnd(n);
|
||||
const commentStartIndex = options.originalText.lastIndexOf("/*", start);
|
||||
const commentEndIndex = options.originalText.indexOf("*/", end);
|
||||
if (commentStartIndex !== -1 && commentEndIndex !== -1) {
|
||||
const comment = options.originalText
|
||||
.slice(commentStartIndex + 2, commentEndIndex)
|
||||
.trim();
|
||||
if (
|
||||
comment.startsWith("::") &&
|
||||
!comment.includes("/*") &&
|
||||
!comment.includes("*/")
|
||||
) {
|
||||
return concat(["/*:: ", printed, " */"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return printTypeParameters(path, options, print, "params");
|
||||
return printed;
|
||||
}
|
||||
|
||||
case "TSTypeParameterDeclaration":
|
||||
@@ -2947,10 +2951,8 @@ function printPathNoParens(path, options, print, args) {
|
||||
return concat(parts);
|
||||
}
|
||||
|
||||
const variance = getFlowVariance(n);
|
||||
|
||||
if (variance) {
|
||||
parts.push(variance);
|
||||
if (n.variance) {
|
||||
parts.push(path.call(print, "variance"));
|
||||
}
|
||||
|
||||
parts.push(path.call(print, "name"));
|
||||
@@ -3402,7 +3404,8 @@ function printPathNoParens(path, options, print, args) {
|
||||
}
|
||||
|
||||
case "PrivateName":
|
||||
return concat(["#", path.call(print, "id")]);
|
||||
// babel use `id`, meriyah use `name`
|
||||
return concat(["#", path.call(print, n.id ? "id" : "name")]);
|
||||
|
||||
// TODO: Temporary auto-generated node type. To remove when typescript-estree has proper support for private fields.
|
||||
case "TSPrivateIdentifier":
|
||||
@@ -3599,7 +3602,10 @@ function printStatementSequence(path, options, print) {
|
||||
if (!options.semi && isClass) {
|
||||
if (classPropMayCauseASIProblems(stmtPath)) {
|
||||
parts.push(";");
|
||||
} else if (stmt.type === "ClassProperty") {
|
||||
} else if (
|
||||
stmt.type === "ClassProperty" ||
|
||||
stmt.type === "FieldDefinition"
|
||||
) {
|
||||
const nextChild = bodyNode.body[i + 1];
|
||||
if (classChildNeedsASIProtection(nextChild)) {
|
||||
parts.push(";");
|
||||
@@ -3868,146 +3874,6 @@ function printTypeAnnotation(path, options, print) {
|
||||
]);
|
||||
}
|
||||
|
||||
function printFunctionParameters(
|
||||
path,
|
||||
print,
|
||||
options,
|
||||
expandArg,
|
||||
printTypeParams
|
||||
) {
|
||||
const functionNode = path.getValue();
|
||||
const parameters = getFunctionParameters(functionNode);
|
||||
const typeParams = printTypeParams
|
||||
? printFunctionTypeParameters(path, options, print)
|
||||
: "";
|
||||
|
||||
if (parameters.length === 0) {
|
||||
return concat([
|
||||
typeParams,
|
||||
"(",
|
||||
comments.printDanglingComments(
|
||||
path,
|
||||
options,
|
||||
/* sameIndent */ true,
|
||||
(comment) =>
|
||||
getNextNonSpaceNonCommentCharacter(
|
||||
options.originalText,
|
||||
comment,
|
||||
locEnd
|
||||
) === ")"
|
||||
),
|
||||
")",
|
||||
]);
|
||||
}
|
||||
|
||||
const parent = path.getParentNode();
|
||||
const isParametersInTestCall = isTestCall(parent);
|
||||
const shouldHugParameters = shouldHugArguments(functionNode);
|
||||
const shouldExpandParameters =
|
||||
expandArg && !parameters.some((node) => node.comments);
|
||||
const printed = [];
|
||||
iterateFunctionParametersPath(path, (parameterPath, index) => {
|
||||
const isLastParameter = index === parameters.length - 1;
|
||||
if (isLastParameter && functionNode.rest) {
|
||||
printed.push("...");
|
||||
}
|
||||
printed.push(parameterPath.call(print));
|
||||
if (isLastParameter) {
|
||||
return;
|
||||
}
|
||||
printed.push(",");
|
||||
if (
|
||||
isParametersInTestCall ||
|
||||
shouldHugParameters ||
|
||||
shouldExpandParameters
|
||||
) {
|
||||
printed.push(" ");
|
||||
} else if (
|
||||
isNextLineEmpty(options.originalText, parameters[index], locEnd)
|
||||
) {
|
||||
printed.push(hardline, hardline);
|
||||
} else {
|
||||
printed.push(line);
|
||||
}
|
||||
});
|
||||
|
||||
// If the parent is a call with the first/last argument expansion and this is the
|
||||
// params of the first/last argument, we don't want the arguments to break and instead
|
||||
// want the whole expression to be on a new line.
|
||||
//
|
||||
// Good: Bad:
|
||||
// verylongcall( verylongcall((
|
||||
// (a, b) => { a,
|
||||
// } b,
|
||||
// }) ) => {
|
||||
// })
|
||||
if (shouldExpandParameters) {
|
||||
return group(
|
||||
concat([
|
||||
removeLines(typeParams),
|
||||
"(",
|
||||
concat(printed.map(removeLines)),
|
||||
")",
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
// Single object destructuring should hug
|
||||
//
|
||||
// function({
|
||||
// a,
|
||||
// b,
|
||||
// c
|
||||
// }) {}
|
||||
const hasNotParameterDecorator = parameters.every((node) => !node.decorators);
|
||||
if (shouldHugParameters && hasNotParameterDecorator) {
|
||||
return concat([typeParams, "(", concat(printed), ")"]);
|
||||
}
|
||||
|
||||
// don't break in specs, eg; `it("should maintain parens around done even when long", (done) => {})`
|
||||
if (isParametersInTestCall) {
|
||||
return concat([typeParams, "(", concat(printed), ")"]);
|
||||
}
|
||||
|
||||
const isFlowShorthandWithOneArg =
|
||||
(isObjectTypePropertyAFunction(parent, options) ||
|
||||
isTypeAnnotationAFunction(parent, options) ||
|
||||
parent.type === "TypeAlias" ||
|
||||
parent.type === "UnionTypeAnnotation" ||
|
||||
parent.type === "TSUnionType" ||
|
||||
parent.type === "IntersectionTypeAnnotation" ||
|
||||
(parent.type === "FunctionTypeAnnotation" &&
|
||||
parent.returnType === functionNode)) &&
|
||||
parameters.length === 1 &&
|
||||
parameters[0].name === null &&
|
||||
// `type q = (this: string) => void;`
|
||||
functionNode.this !== parameters[0] &&
|
||||
parameters[0].typeAnnotation &&
|
||||
functionNode.typeParameters === null &&
|
||||
isSimpleType(parameters[0].typeAnnotation) &&
|
||||
!functionNode.rest;
|
||||
|
||||
if (isFlowShorthandWithOneArg) {
|
||||
if (options.arrowParens === "always") {
|
||||
return concat(["(", concat(printed), ")"]);
|
||||
}
|
||||
return concat(printed);
|
||||
}
|
||||
|
||||
return concat([
|
||||
typeParams,
|
||||
"(",
|
||||
indent(concat([softline, concat(printed)])),
|
||||
ifBreak(
|
||||
!hasRestParameter(functionNode) && shouldPrintComma(options, "all")
|
||||
? ","
|
||||
: ""
|
||||
),
|
||||
softline,
|
||||
")",
|
||||
]);
|
||||
}
|
||||
|
||||
function shouldPrintParamsWithoutParens(path, options) {
|
||||
if (options.arrowParens === "always") {
|
||||
return false;
|
||||
@@ -4139,6 +4005,7 @@ function printExportDeclaration(path, options, print) {
|
||||
parts.push(decl.exportKind === "type" ? "type " : "");
|
||||
parts.push(printModuleSpecifiers(path, options, print));
|
||||
parts.push(printModuleSource(path, options, print));
|
||||
parts.push(printImportAssertions(path, options, print));
|
||||
parts.push(semi);
|
||||
}
|
||||
|
||||
@@ -4206,8 +4073,8 @@ function printTypeParameters(path, options, print, paramsKey) {
|
||||
if (!hasDanglingComments(n)) {
|
||||
return "";
|
||||
}
|
||||
const hasOnlyBlockComments = n.comments.every(
|
||||
handleComments.isBlockComment
|
||||
const hasOnlyBlockComments = n.comments.every((comment) =>
|
||||
isBlockComment(comment)
|
||||
);
|
||||
const printed = comments.printDanglingComments(
|
||||
path,
|
||||
@@ -5114,37 +4981,6 @@ function shouldHugType(node) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function shouldHugArguments(fun) {
|
||||
if (!fun) {
|
||||
return false;
|
||||
}
|
||||
const parameters = getFunctionParameters(fun);
|
||||
if (parameters.length !== 1) {
|
||||
return false;
|
||||
}
|
||||
const param = parameters[0];
|
||||
return (
|
||||
!param.comments &&
|
||||
(param.type === "ObjectPattern" ||
|
||||
param.type === "ArrayPattern" ||
|
||||
(param.type === "Identifier" &&
|
||||
param.typeAnnotation &&
|
||||
(param.typeAnnotation.type === "TypeAnnotation" ||
|
||||
param.typeAnnotation.type === "TSTypeAnnotation") &&
|
||||
isObjectType(param.typeAnnotation.typeAnnotation)) ||
|
||||
(param.type === "FunctionTypeParam" &&
|
||||
isObjectType(param.typeAnnotation)) ||
|
||||
(param.type === "AssignmentPattern" &&
|
||||
(param.left.type === "ObjectPattern" ||
|
||||
param.left.type === "ArrayPattern") &&
|
||||
(param.right.type === "Identifier" ||
|
||||
(param.right.type === "ObjectExpression" &&
|
||||
param.right.properties.length === 0) ||
|
||||
(param.right.type === "ArrayExpression" &&
|
||||
param.right.elements.length === 0))))
|
||||
);
|
||||
}
|
||||
|
||||
function printArrayItems(path, options, printPath, print) {
|
||||
const printedElements = [];
|
||||
let separatorParts = [];
|
||||
@@ -5201,9 +5037,7 @@ function printReturnAndThrowArgument(path, options, print) {
|
||||
|
||||
const lastComment =
|
||||
Array.isArray(node.comments) && node.comments[node.comments.length - 1];
|
||||
const isLastCommentLine =
|
||||
lastComment &&
|
||||
(lastComment.type === "CommentLine" || lastComment.type === "Line");
|
||||
const isLastCommentLine = lastComment && isLineComment(lastComment);
|
||||
|
||||
if (isLastCommentLine) {
|
||||
parts.push(semi);
|
||||
@@ -5266,41 +5100,38 @@ function canAttachComment(node) {
|
||||
function printComment(commentPath, options) {
|
||||
const comment = commentPath.getValue();
|
||||
|
||||
switch (comment.type) {
|
||||
case "CommentBlock":
|
||||
case "Block": {
|
||||
if (isIndentableBlockComment(comment)) {
|
||||
const printed = printIndentableBlockComment(comment);
|
||||
// We need to prevent an edge case of a previous trailing comment
|
||||
// printed as a `lineSuffix` which causes the comments to be
|
||||
// interleaved. See https://github.com/prettier/prettier/issues/4412
|
||||
if (
|
||||
comment.trailing &&
|
||||
!hasNewline(options.originalText, locStart(comment), {
|
||||
backwards: true,
|
||||
})
|
||||
) {
|
||||
return concat([hardline, printed]);
|
||||
}
|
||||
return printed;
|
||||
}
|
||||
|
||||
const commentEnd = locEnd(comment);
|
||||
const isInsideFlowComment =
|
||||
options.originalText.slice(commentEnd - 3, commentEnd) === "*-/";
|
||||
|
||||
return "/*" + comment.value + (isInsideFlowComment ? "*-/" : "*/");
|
||||
}
|
||||
case "CommentLine":
|
||||
case "Line":
|
||||
// Supports `//`, `#!`, `<!--`, and `-->`
|
||||
return options.originalText
|
||||
.slice(locStart(comment), locEnd(comment))
|
||||
.trimEnd();
|
||||
default:
|
||||
/* istanbul ignore next */
|
||||
throw new Error("Not a comment: " + JSON.stringify(comment));
|
||||
if (isLineComment(comment)) {
|
||||
// Supports `//`, `#!`, `<!--`, and `-->`
|
||||
return options.originalText
|
||||
.slice(locStart(comment), locEnd(comment))
|
||||
.trimEnd();
|
||||
}
|
||||
|
||||
if (isBlockComment(comment)) {
|
||||
if (isIndentableBlockComment(comment)) {
|
||||
const printed = printIndentableBlockComment(comment);
|
||||
// We need to prevent an edge case of a previous trailing comment
|
||||
// printed as a `lineSuffix` which causes the comments to be
|
||||
// interleaved. See https://github.com/prettier/prettier/issues/4412
|
||||
if (
|
||||
comment.trailing &&
|
||||
!hasNewline(options.originalText, locStart(comment), {
|
||||
backwards: true,
|
||||
})
|
||||
) {
|
||||
return concat([hardline, printed]);
|
||||
}
|
||||
return printed;
|
||||
}
|
||||
|
||||
const commentEnd = locEnd(comment);
|
||||
const isInsideFlowComment =
|
||||
options.originalText.slice(commentEnd - 3, commentEnd) === "*-/";
|
||||
return "/*" + comment.value + (isInsideFlowComment ? "*-/" : "*/");
|
||||
}
|
||||
|
||||
/* istanbul ignore next */
|
||||
throw new Error("Not a comment: " + JSON.stringify(comment));
|
||||
}
|
||||
|
||||
function isIndentableBlockComment(comment) {
|
||||
@@ -5339,7 +5170,7 @@ module.exports = {
|
||||
willPrintOwnComments,
|
||||
canAttachComment,
|
||||
printComment,
|
||||
isBlockComment: handleComments.isBlockComment,
|
||||
isBlockComment,
|
||||
handleComments: {
|
||||
ownLine: handleComments.handleOwnLineComment,
|
||||
endOfLine: handleComments.handleEndOfLineComment,
|
||||
|
||||
Vendored
+19
-1
@@ -14,7 +14,25 @@ type AdditionalFields = {
|
||||
leadingComments?: ReadonlyArray<Comment> | Comment[];
|
||||
};
|
||||
|
||||
export type Comment = (ESTree.Comment | Babel.Comment | TSESTree.Comment) & {
|
||||
type MeriyahComment = {
|
||||
value: string;
|
||||
start: number;
|
||||
end: number;
|
||||
range: number[];
|
||||
type:
|
||||
| "MultiLine"
|
||||
| "SingleLine"
|
||||
| "HashbangComment"
|
||||
| "HTMLOpen"
|
||||
| "HTMLClose";
|
||||
};
|
||||
|
||||
export type Comment = (
|
||||
| ESTree.Comment
|
||||
| Babel.Comment
|
||||
| TSESTree.Comment
|
||||
| MeriyahComment
|
||||
) & {
|
||||
printed?: boolean;
|
||||
trailing?: boolean;
|
||||
leading?: boolean;
|
||||
|
||||
+48
-69
@@ -9,7 +9,7 @@ const {
|
||||
hasNodeIgnoreComment,
|
||||
skipWhitespace,
|
||||
} = require("../common/util");
|
||||
const { locStart, locEnd } = require("./loc");
|
||||
const { locStart, locEnd, hasSameLocStart } = require("./loc");
|
||||
|
||||
/**
|
||||
* @typedef {import("./types/estree").Node} Node
|
||||
@@ -56,6 +56,7 @@ function hasFlowShorthandAnnotationComment(node) {
|
||||
node.extra &&
|
||||
node.extra.parenthesized &&
|
||||
node.trailingComments &&
|
||||
isBlockComment(node.trailingComments[0]) &&
|
||||
FLOW_SHORTHAND_ANNOTATION.test(node.trailingComments[0].value)
|
||||
);
|
||||
}
|
||||
@@ -65,7 +66,11 @@ function hasFlowShorthandAnnotationComment(node) {
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function hasFlowAnnotationComment(comments) {
|
||||
return comments && FLOW_ANNOTATION.test(comments[0].value);
|
||||
return (
|
||||
comments &&
|
||||
isBlockComment(comments[0]) &&
|
||||
FLOW_ANNOTATION.test(comments[0].value)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,6 +158,35 @@ function getLeftSidePathName(path, node) {
|
||||
throw new Error("Unexpected node has no left side.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Comment} comment
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isBlockComment(comment) {
|
||||
return (
|
||||
comment.type === "Block" ||
|
||||
comment.type === "CommentBlock" ||
|
||||
// `meriyah`
|
||||
comment.type === "MultiLine"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Comment} comment
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isLineComment(comment) {
|
||||
return (
|
||||
comment.type === "Line" ||
|
||||
comment.type === "CommentLine" ||
|
||||
// `meriyah` has `SingleLine`, `HashbangComment`, `HTMLOpen`, and `HTMLClose`
|
||||
comment.type === "SingleLine" ||
|
||||
comment.type === "HashbangComment" ||
|
||||
comment.type === "HTMLOpen" ||
|
||||
comment.type === "HTMLClose"
|
||||
);
|
||||
}
|
||||
|
||||
const exportDeclarationTypes = new Set([
|
||||
"ExportDefaultDeclaration",
|
||||
"ExportDefaultSpecifier",
|
||||
@@ -161,10 +195,6 @@ const exportDeclarationTypes = new Set([
|
||||
"ExportAllDeclaration",
|
||||
]);
|
||||
|
||||
function isBlockComment(comment) {
|
||||
return comment.type === "Block" || comment.type === "CommentBlock";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node
|
||||
* @returns {boolean}
|
||||
@@ -341,39 +371,10 @@ function isGetterOrSetter(node) {
|
||||
return node.kind === "get" || node.kind === "set";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} nodeA
|
||||
* @param {Node} nodeB
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function sameLocStart(nodeA, nodeB, { locStart }) {
|
||||
return locStart(nodeA) === locStart(nodeB);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} nodeA
|
||||
* @param {Node} nodeB
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function sameLocEnd(nodeA, nodeB, { locEnd }) {
|
||||
return locEnd(nodeA) === locEnd(nodeB);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} nodeA
|
||||
* @param {Node} nodeB
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function hasSameLoc(nodeA, nodeB, options) {
|
||||
return (
|
||||
sameLocStart(nodeA, nodeB, options) && sameLocEnd(nodeA, nodeB, options)
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: This is a bad hack and we need a better way to distinguish between
|
||||
// arrow functions and otherwise
|
||||
function isFunctionNotation(node, options) {
|
||||
return isGetterOrSetter(node) || sameLocStart(node, node.value, options);
|
||||
function isFunctionNotation(node) {
|
||||
return isGetterOrSetter(node) || hasSameLocStart(node, node.value);
|
||||
}
|
||||
|
||||
// Hack to differentiate between the following two which have the same ast
|
||||
@@ -383,25 +384,25 @@ function isFunctionNotation(node, options) {
|
||||
* @param {Node} node
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isObjectTypePropertyAFunction(node, options) {
|
||||
function isObjectTypePropertyAFunction(node) {
|
||||
return (
|
||||
(node.type === "ObjectTypeProperty" ||
|
||||
node.type === "ObjectTypeInternalSlot") &&
|
||||
node.value.type === "FunctionTypeAnnotation" &&
|
||||
!node.static &&
|
||||
!isFunctionNotation(node, options)
|
||||
!isFunctionNotation(node)
|
||||
);
|
||||
}
|
||||
|
||||
// Hack to differentiate between the following two which have the same ast
|
||||
// declare function f(a): void;
|
||||
// var f: (a) => void;
|
||||
function isTypeAnnotationAFunction(node, options) {
|
||||
function isTypeAnnotationAFunction(node) {
|
||||
return (
|
||||
(node.type === "TypeAnnotation" || node.type === "TSTypeAnnotation") &&
|
||||
node.typeAnnotation.type === "FunctionTypeAnnotation" &&
|
||||
!node.static &&
|
||||
!sameLocStart(node, node.typeAnnotation, options)
|
||||
!hasSameLocStart(node, node.typeAnnotation)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -698,30 +699,6 @@ function isSimpleTemplateLiteral(node) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ObjectTypeProperty} node
|
||||
*/
|
||||
function getFlowVariance(node) {
|
||||
if (!node.variance) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Babel 7.0 currently uses variance node type, and flow should
|
||||
// follow suit soon:
|
||||
// https://github.com/babel/babel/issues/4722
|
||||
const variance = node.variance.kind || node.variance;
|
||||
|
||||
switch (variance) {
|
||||
case "plus":
|
||||
return "+";
|
||||
case "minus":
|
||||
return "-";
|
||||
default:
|
||||
/* istanbul ignore next */
|
||||
return variance;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {FastPath} path
|
||||
* @returns {boolean}
|
||||
@@ -729,7 +706,7 @@ function getFlowVariance(node) {
|
||||
function classPropMayCauseASIProblems(path) {
|
||||
const node = path.getNode();
|
||||
|
||||
if (node.type !== "ClassProperty") {
|
||||
if (node.type !== "ClassProperty" && node.type !== "FieldDefinition") {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -766,6 +743,7 @@ function classChildNeedsASIProtection(node) {
|
||||
}
|
||||
switch (node.type) {
|
||||
case "ClassProperty":
|
||||
case "FieldDefinition":
|
||||
case "TSAbstractClassProperty":
|
||||
return node.computed;
|
||||
case "MethodDefinition": // Flow
|
||||
@@ -1009,7 +987,9 @@ function isStringPropSafeToUnquote(node, options) {
|
||||
)) ||
|
||||
(isSimpleNumber(node.key.value) &&
|
||||
String(Number(node.key.value)) === node.key.value &&
|
||||
(options.parser === "babel" || options.parser === "espree")))
|
||||
(options.parser === "babel" ||
|
||||
options.parser === "espree" ||
|
||||
options.parser === "meriyah")))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1471,7 +1451,6 @@ function iterateFunctionParametersPath(path, iteratee) {
|
||||
module.exports = {
|
||||
classChildNeedsASIProtection,
|
||||
classPropMayCauseASIProblems,
|
||||
getFlowVariance,
|
||||
getFunctionParameters,
|
||||
iterateFunctionParametersPath,
|
||||
hasRestParameter,
|
||||
@@ -1488,12 +1467,12 @@ module.exports = {
|
||||
hasNgSideEffect,
|
||||
hasNode,
|
||||
hasPrettierIgnore,
|
||||
hasSameLoc,
|
||||
hasTrailingComment,
|
||||
hasTrailingLineComment,
|
||||
identity,
|
||||
isBinaryish,
|
||||
isBlockComment,
|
||||
isLineComment,
|
||||
isCallOrOptionalCallExpression,
|
||||
isEmptyJSXElement,
|
||||
isExportDeclaration,
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
"use strict";
|
||||
|
||||
const { isFrontMatterNode } = require("../common/util");
|
||||
const { startWithPragma } = require("./pragma");
|
||||
|
||||
const ignoredProperties = new Set([
|
||||
"position",
|
||||
"raw", // front-matter
|
||||
]);
|
||||
function clean(ast, newObj, parent) {
|
||||
// for codeblock
|
||||
if (
|
||||
ast.type === "front-matter" ||
|
||||
ast.type === "code" ||
|
||||
ast.type === "yaml" ||
|
||||
ast.type === "import" ||
|
||||
ast.type === "export" ||
|
||||
ast.type === "jsx"
|
||||
) {
|
||||
delete newObj.value;
|
||||
}
|
||||
|
||||
if (ast.type === "list") {
|
||||
delete newObj.isAligned;
|
||||
}
|
||||
|
||||
if (ast.type === "list" || ast.type === "listItem") {
|
||||
delete newObj.spread;
|
||||
delete newObj.loose;
|
||||
}
|
||||
|
||||
// texts can be splitted or merged
|
||||
if (ast.type === "text") {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (ast.type === "inlineCode") {
|
||||
newObj.value = ast.value.replace(/[\t\n ]+/g, " ");
|
||||
}
|
||||
|
||||
if (ast.type === "wikiLink") {
|
||||
newObj.value = ast.value.trim().replace(/[\t\n]+/g, " ");
|
||||
}
|
||||
|
||||
if (ast.type === "definition" || ast.type === "linkReference") {
|
||||
newObj.label = ast.label
|
||||
.trim()
|
||||
.replace(/[\t\n ]+/g, " ")
|
||||
.toLowerCase();
|
||||
}
|
||||
|
||||
if (
|
||||
(ast.type === "definition" ||
|
||||
ast.type === "link" ||
|
||||
ast.type === "image") &&
|
||||
ast.title
|
||||
) {
|
||||
newObj.title = ast.title.replace(/\\(["')])/g, "$1");
|
||||
}
|
||||
|
||||
// for insert pragma
|
||||
if (
|
||||
parent &&
|
||||
parent.type === "root" &&
|
||||
parent.children.length > 0 &&
|
||||
(parent.children[0] === ast ||
|
||||
(isFrontMatterNode(parent.children[0]) && parent.children[1] === ast)) &&
|
||||
ast.type === "html" &&
|
||||
startWithPragma(ast.value)
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
clean.ignoredProperties = ignoredProperties;
|
||||
|
||||
module.exports = clean;
|
||||
@@ -25,10 +25,11 @@ const {
|
||||
utils: { normalizeDoc },
|
||||
printer: { printDocToString },
|
||||
} = require("../document");
|
||||
const { replaceEndOfLineWith, isFrontMatterNode } = require("../common/util");
|
||||
const { replaceEndOfLineWith } = require("../common/util");
|
||||
const embed = require("./embed");
|
||||
const pragma = require("./pragma");
|
||||
const { insertPragma } = require("./pragma");
|
||||
const preprocess = require("./preprocess");
|
||||
const clean = require("./clean");
|
||||
const {
|
||||
getFencedCodeBlockValue,
|
||||
hasGitDiffFriendlyOrderedList,
|
||||
@@ -935,74 +936,6 @@ function clamp(value, min, max) {
|
||||
return value < min ? min : value > max ? max : value;
|
||||
}
|
||||
|
||||
function clean(ast, newObj, parent) {
|
||||
delete newObj.position;
|
||||
delete newObj.raw; // front-matter
|
||||
|
||||
// for codeblock
|
||||
if (
|
||||
ast.type === "front-matter" ||
|
||||
ast.type === "code" ||
|
||||
ast.type === "yaml" ||
|
||||
ast.type === "import" ||
|
||||
ast.type === "export" ||
|
||||
ast.type === "jsx"
|
||||
) {
|
||||
delete newObj.value;
|
||||
}
|
||||
|
||||
if (ast.type === "list") {
|
||||
delete newObj.isAligned;
|
||||
}
|
||||
|
||||
if (ast.type === "list" || ast.type === "listItem") {
|
||||
delete newObj.spread;
|
||||
delete newObj.loose;
|
||||
}
|
||||
|
||||
// texts can be splitted or merged
|
||||
if (ast.type === "text") {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (ast.type === "inlineCode") {
|
||||
newObj.value = ast.value.replace(/[\t\n ]+/g, " ");
|
||||
}
|
||||
|
||||
if (ast.type === "wikiLink") {
|
||||
newObj.value = ast.value.trim().replace(/[\t\n]+/g, " ");
|
||||
}
|
||||
|
||||
if (ast.type === "definition" || ast.type === "linkReference") {
|
||||
newObj.label = ast.label
|
||||
.trim()
|
||||
.replace(/[\t\n ]+/g, " ")
|
||||
.toLowerCase();
|
||||
}
|
||||
|
||||
if (
|
||||
(ast.type === "definition" ||
|
||||
ast.type === "link" ||
|
||||
ast.type === "image") &&
|
||||
ast.title
|
||||
) {
|
||||
newObj.title = ast.title.replace(/\\(["')])/g, "$1");
|
||||
}
|
||||
|
||||
// for insert pragma
|
||||
if (
|
||||
parent &&
|
||||
parent.type === "root" &&
|
||||
parent.children.length > 0 &&
|
||||
(parent.children[0] === ast ||
|
||||
(isFrontMatterNode(parent.children[0]) && parent.children[1] === ast)) &&
|
||||
ast.type === "html" &&
|
||||
pragma.startWithPragma(ast.value)
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function hasPrettierIgnore(path) {
|
||||
const index = +path.getName();
|
||||
|
||||
@@ -1020,5 +953,5 @@ module.exports = {
|
||||
embed,
|
||||
massageAstNode: clean,
|
||||
hasPrettierIgnore,
|
||||
insertPragma: pragma.insertPragma,
|
||||
insertPragma,
|
||||
};
|
||||
@@ -130,6 +130,7 @@ const options = {
|
||||
{ value: "babel-ts", since: "2.0.0", description: "TypeScript" },
|
||||
{ value: "typescript", since: "1.4.0", description: "TypeScript" },
|
||||
{ value: "espree", since: "2.2.0", description: "JavaScript" },
|
||||
{ value: "meriyah", since: "2.2.0", description: "JavaScript" },
|
||||
{ value: "css", since: "1.7.1", description: "CSS" },
|
||||
{ value: "less", since: "1.7.1", description: "Less" },
|
||||
{ value: "scss", since: "1.7.1", description: "SCSS" },
|
||||
|
||||
@@ -120,6 +120,7 @@ function isSourceElement(opts, node) {
|
||||
case "babel-ts":
|
||||
case "typescript":
|
||||
case "espree":
|
||||
case "meriyah":
|
||||
return isJsSourceElement(node.type);
|
||||
case "json":
|
||||
return jsonSourceElements.has(node.type);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
exports[`test.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["flow"]
|
||||
parsers: ["flow", "babel-flow"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
|
||||
@@ -1 +1 @@
|
||||
run_spec(__dirname, ["flow"]);
|
||||
run_spec(__dirname, ["flow", "babel-flow"]);
|
||||
@@ -54,6 +54,17 @@ function baz(this: number, ...a) {}
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`function_type.js - {"trailingComma":"all"} [babel-flow] format 1`] = `
|
||||
"Unexpected token, expected \\")\\" (3:16)
|
||||
1 | // @flow
|
||||
2 |
|
||||
> 3 | type T = (this : number, a : string, b : number) => void
|
||||
| ^
|
||||
4 |
|
||||
5 | type U = (this : number, ...c : any) => void
|
||||
6 | "
|
||||
`;
|
||||
|
||||
exports[`function_type.js - {"trailingComma":"all"} format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["flow", "babel-flow"]
|
||||
@@ -81,6 +92,17 @@ type V = (this: number) => void;
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`line_break.js - {"trailingComma":"all"} [babel-flow] format 1`] = `
|
||||
"Unexpected token, expected \\")\\" (3:15)
|
||||
1 | // @flow
|
||||
2 |
|
||||
> 3 | type T = (this: boolean,
|
||||
| ^
|
||||
4 | a: number,
|
||||
5 |
|
||||
6 | b: number,"
|
||||
`;
|
||||
|
||||
exports[`line_break.js - {"trailingComma":"all"} format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["flow", "babel-flow"]
|
||||
@@ -173,6 +195,17 @@ class A {
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`union_type.js - {"trailingComma":"all"} [babel-flow] format 1`] = `
|
||||
"Unexpected token, expected \\")\\" (4:7)
|
||||
2 |
|
||||
3 | type A = (
|
||||
> 4 | this: | SupperLongLongLongLongLongLongLongLongLongLongLongType | FooBarBazLorem12345,
|
||||
| ^
|
||||
5 | b: number,
|
||||
6 | ) => boolean;
|
||||
7 | "
|
||||
`;
|
||||
|
||||
exports[`union_type.js - {"trailingComma":"all"} format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["flow", "babel-flow"]
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
exports[`variance.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["flow", "babel"]
|
||||
parsers: ["flow", "babel-flow"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
|
||||
@@ -1 +1 @@
|
||||
run_spec(__dirname, ["flow", "babel"]);
|
||||
run_spec(__dirname, ["flow", "babel-flow"]);
|
||||
@@ -302,6 +302,26 @@ promise.then((result) =>
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`class-property.js [espree] format 1`] = `
|
||||
"Unexpected token = (3:22)
|
||||
1 | const composition = (ViewComponent, ContainerComponent) =>
|
||||
2 | class extends React.Component {
|
||||
> 3 | static propTypes = {};
|
||||
| ^
|
||||
4 | };
|
||||
5 | "
|
||||
`;
|
||||
|
||||
exports[`class-property.js - {"arrowParens":"always"} [espree] format 1`] = `
|
||||
"Unexpected token = (3:22)
|
||||
1 | const composition = (ViewComponent, ContainerComponent) =>
|
||||
2 | class extends React.Component {
|
||||
> 3 | static propTypes = {};
|
||||
| ^
|
||||
4 | };
|
||||
5 | "
|
||||
`;
|
||||
|
||||
exports[`class-property.js - {"arrowParens":"always"} format 1`] = `
|
||||
====================================options=====================================
|
||||
arrowParens: "always"
|
||||
@@ -323,6 +343,16 @@ const composition = (ViewComponent, ContainerComponent) =>
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`class-property.js - {"trailingComma":"all"} [espree] format 1`] = `
|
||||
"Unexpected token = (3:22)
|
||||
1 | const composition = (ViewComponent, ContainerComponent) =>
|
||||
2 | class extends React.Component {
|
||||
> 3 | static propTypes = {};
|
||||
| ^
|
||||
4 | };
|
||||
5 | "
|
||||
`;
|
||||
|
||||
exports[`class-property.js - {"trailingComma":"all"} format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "flow", "typescript"]
|
||||
|
||||
@@ -1,5 +1,23 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`arrows-bind.js [espree] format 1`] = `
|
||||
"Unexpected token : (1:9)
|
||||
> 1 | a => ({}::b()\`\`[''].c++ && 0 ? 0 : 0);
|
||||
| ^
|
||||
2 | (a => b)::c;
|
||||
3 | a::(b => c);
|
||||
4 | "
|
||||
`;
|
||||
|
||||
exports[`arrows-bind.js [meriyah] format 1`] = `
|
||||
"[1:9]: Expected ')' (1:9)
|
||||
> 1 | a => ({}::b()\`\`[''].c++ && 0 ? 0 : 0);
|
||||
| ^
|
||||
2 | (a => b)::c;
|
||||
3 | a::(b => c);
|
||||
4 | "
|
||||
`;
|
||||
|
||||
exports[`arrows-bind.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
|
||||
@@ -1 +1 @@
|
||||
run_spec(__dirname, ["babel"], { errors: { espree: true } });
|
||||
run_spec(__dirname, ["babel"], { errors: { espree: true, meriyah: true } });
|
||||
@@ -1,5 +1,21 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`newline-before-arrow.js [espree] format 1`] = `
|
||||
"Unexpected token => (2:1)
|
||||
1 | async x
|
||||
> 2 | => x
|
||||
| ^
|
||||
3 | "
|
||||
`;
|
||||
|
||||
exports[`newline-before-arrow.js [meriyah] format 1`] = `
|
||||
"[2:2]: No line break is allowed after '=>' (2:2)
|
||||
1 | async x
|
||||
> 2 | => x
|
||||
| ^
|
||||
3 | "
|
||||
`;
|
||||
|
||||
exports[`newline-before-arrow.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
run_spec(__dirname, ["babel"], {
|
||||
errors: { espree: ["newline-before-arrow.js"] },
|
||||
errors: {
|
||||
espree: ["newline-before-arrow.js"],
|
||||
meriyah: ["newline-before-arrow.js"],
|
||||
},
|
||||
});
|
||||
@@ -292,6 +292,17 @@ const alsoGoodPrecision = 9007199254740993n;
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`class-properties.js [espree] format 1`] = `
|
||||
"Unexpected token = (5:22)
|
||||
3 | class Bork {
|
||||
4 | //Property initializer syntax
|
||||
> 5 | instanceProperty = \\"bork\\";
|
||||
| ^
|
||||
6 | boundFunction = () => {
|
||||
7 | return this.instanceProperty;
|
||||
8 | };"
|
||||
`;
|
||||
|
||||
exports[`class-properties.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "babel-ts", "babel-flow"]
|
||||
@@ -356,6 +367,27 @@ console.log(Bork.staticFunction()); // > "babelIsCool"
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`class-static-block.js [espree] format 1`] = `
|
||||
"Unexpected character '#' (2:10)
|
||||
1 | class C {
|
||||
> 2 | static #x = 42;
|
||||
| ^
|
||||
3 | static y;
|
||||
4 | static {
|
||||
5 | try {"
|
||||
`;
|
||||
|
||||
exports[`class-static-block.js [meriyah] format 1`] = `
|
||||
"[4:10]: Unexpected token: '{' (4:10)
|
||||
2 | static #x = 42;
|
||||
3 | static y;
|
||||
> 4 | static {
|
||||
| ^
|
||||
5 | try {
|
||||
6 | this.y = doSomethingWith(this.#x);
|
||||
7 | } catch {"
|
||||
`;
|
||||
|
||||
exports[`class-static-block.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "babel-ts", "babel-flow"]
|
||||
@@ -390,6 +422,28 @@ class C {
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`decimal.js [espree] format 1`] = `
|
||||
"Identifier directly after number (3:4)
|
||||
1 | // https://github.com/babel/babel/pull/11640
|
||||
2 |
|
||||
> 3 | 100m;
|
||||
| ^
|
||||
4 | 9223372036854775807m;
|
||||
5 | 0.m;
|
||||
6 | 3.1415926535897932m;"
|
||||
`;
|
||||
|
||||
exports[`decimal.js [meriyah] format 1`] = `
|
||||
"[3:3]: No identifiers allowed directly after numeric literal (3:3)
|
||||
1 | // https://github.com/babel/babel/pull/11640
|
||||
2 |
|
||||
> 3 | 100m;
|
||||
| ^
|
||||
4 | 9223372036854775807m;
|
||||
5 | 0.m;
|
||||
6 | 3.1415926535897932m;"
|
||||
`;
|
||||
|
||||
exports[`decimal.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "babel-ts", "babel-flow"]
|
||||
@@ -453,6 +507,17 @@ typeof 1m === "decimal128";
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`decorators.js [espree] format 1`] = `
|
||||
"Unexpected character '@' (3:1)
|
||||
1 | // https://babeljs.io/docs/en/babel-plugin-proposal-decorators
|
||||
2 |
|
||||
> 3 | @annotation
|
||||
| ^
|
||||
4 | class MyClass { }
|
||||
5 |
|
||||
6 | function annotation(target) {"
|
||||
`;
|
||||
|
||||
exports[`decorators.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "babel-ts", "babel-flow"]
|
||||
@@ -523,6 +588,28 @@ function enumerable(value) {
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`do-expressions.js [espree] format 1`] = `
|
||||
"Unexpected token do (3:9)
|
||||
1 | // https://babeljs.io/docs/en/babel-plugin-proposal-do-expressions
|
||||
2 |
|
||||
> 3 | let a = do {
|
||||
| ^
|
||||
4 | if(x > 10) {
|
||||
5 | 'big';
|
||||
6 | } else {"
|
||||
`;
|
||||
|
||||
exports[`do-expressions.js [meriyah] format 1`] = `
|
||||
"[3:10]: Unexpected token: 'do' (3:10)
|
||||
1 | // https://babeljs.io/docs/en/babel-plugin-proposal-do-expressions
|
||||
2 |
|
||||
> 3 | let a = do {
|
||||
| ^
|
||||
4 | if(x > 10) {
|
||||
5 | 'big';
|
||||
6 | } else {"
|
||||
`;
|
||||
|
||||
exports[`do-expressions.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "babel-ts", "babel-flow"]
|
||||
@@ -585,6 +672,24 @@ import(prettier).then((module) => console.log(module));
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`export-default-from.js [espree] format 1`] = `
|
||||
"Unexpected token v (4:8)
|
||||
2 |
|
||||
3 |
|
||||
> 4 | export v from 'mod';
|
||||
| ^
|
||||
5 | "
|
||||
`;
|
||||
|
||||
exports[`export-default-from.js [meriyah] format 1`] = `
|
||||
"[4:8]: Unexpected token: 'identifier' (4:8)
|
||||
2 |
|
||||
3 |
|
||||
> 4 | export v from 'mod';
|
||||
| ^
|
||||
5 | "
|
||||
`;
|
||||
|
||||
exports[`export-default-from.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "babel-ts", "babel-flow"]
|
||||
@@ -622,6 +727,24 @@ export * as ns from "mod";
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`flow.js [espree] format 1`] = `
|
||||
"Unexpected token : (3:17)
|
||||
1 | // https://babeljs.io/docs/en/babel-preset-flow
|
||||
2 |
|
||||
> 3 | function foo(one: any, two: number, three?): string {}
|
||||
| ^
|
||||
4 | "
|
||||
`;
|
||||
|
||||
exports[`flow.js [meriyah] format 1`] = `
|
||||
"[3:17]: Expected ')' (3:17)
|
||||
1 | // https://babeljs.io/docs/en/babel-preset-flow
|
||||
2 |
|
||||
> 3 | function foo(one: any, two: number, three?): string {}
|
||||
| ^
|
||||
4 | "
|
||||
`;
|
||||
|
||||
exports[`flow.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "babel-ts", "babel-flow"]
|
||||
@@ -640,6 +763,28 @@ function foo(one: any, two: number, three?): string {}
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`function-bind.js [espree] format 1`] = `
|
||||
"Unexpected token : (3:5)
|
||||
1 | // https://babeljs.io/docs/en/babel-plugin-proposal-function-bind
|
||||
2 |
|
||||
> 3 | obj::func
|
||||
| ^
|
||||
4 | // is equivalent to:
|
||||
5 | func.bind(obj)
|
||||
6 | "
|
||||
`;
|
||||
|
||||
exports[`function-bind.js [meriyah] format 1`] = `
|
||||
"[3:5]: Unexpected token: ':' (3:5)
|
||||
1 | // https://babeljs.io/docs/en/babel-plugin-proposal-function-bind
|
||||
2 |
|
||||
> 3 | obj::func
|
||||
| ^
|
||||
4 | // is equivalent to:
|
||||
5 | func.bind(obj)
|
||||
6 | "
|
||||
`;
|
||||
|
||||
exports[`function-bind.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "babel-ts", "babel-flow"]
|
||||
@@ -685,6 +830,28 @@ obj.func.call(obj, val);
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`function-sent.js [espree] format 1`] = `
|
||||
"Unexpected token . (4:33)
|
||||
2 |
|
||||
3 | function* generator() {
|
||||
> 4 | console.log(\\"Sent\\", function.sent);
|
||||
| ^
|
||||
5 | console.log(\\"Yield\\", yield);
|
||||
6 | }
|
||||
7 | "
|
||||
`;
|
||||
|
||||
exports[`function-sent.js [meriyah] format 1`] = `
|
||||
"[4:33]: Expected '(' (4:33)
|
||||
2 |
|
||||
3 | function* generator() {
|
||||
> 4 | console.log(\\"Sent\\", function.sent);
|
||||
| ^
|
||||
5 | console.log(\\"Yield\\", yield);
|
||||
6 | }
|
||||
7 | "
|
||||
`;
|
||||
|
||||
exports[`function-sent.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "babel-ts", "babel-flow"]
|
||||
@@ -717,6 +884,20 @@ iterator.next(2); // Logs "Yield 2"
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`import-assertions-dynamic.js [espree] format 1`] = `
|
||||
"Unexpected token , (1:20)
|
||||
> 1 | import(\\"./foo.json\\", { assert: { type: \\"json\\" } });
|
||||
| ^
|
||||
2 | "
|
||||
`;
|
||||
|
||||
exports[`import-assertions-dynamic.js [meriyah] format 1`] = `
|
||||
"[1:20]: Expected ')' (1:20)
|
||||
> 1 | import(\\"./foo.json\\", { assert: { type: \\"json\\" } });
|
||||
| ^
|
||||
2 | "
|
||||
`;
|
||||
|
||||
exports[`import-assertions-dynamic.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "babel-ts", "babel-flow"]
|
||||
@@ -731,6 +912,20 @@ import("./foo.json", { assert: { type: "json" } });
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`import-assertions-static.js [espree] format 1`] = `
|
||||
"Unexpected token assert (1:31)
|
||||
> 1 | import json from \\"./foo.json\\" assert { type: \\"json\\" };
|
||||
| ^
|
||||
2 | "
|
||||
`;
|
||||
|
||||
exports[`import-assertions-static.js [meriyah] format 1`] = `
|
||||
"[1:36]: Unexpected token: 'identifier' (1:36)
|
||||
> 1 | import json from \\"./foo.json\\" assert { type: \\"json\\" };
|
||||
| ^
|
||||
2 | "
|
||||
`;
|
||||
|
||||
exports[`import-assertions-static.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "babel-ts", "babel-flow"]
|
||||
@@ -819,6 +1014,17 @@ var profile = (
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`logical-assignment-operators.js [meriyah] format 1`] = `
|
||||
"[3:5]: Unexpected token: '=' (3:5)
|
||||
1 | // https://babeljs.io/docs/en/babel-plugin-proposal-logical-assignment-operators
|
||||
2 |
|
||||
> 3 | a ||= b;
|
||||
| ^
|
||||
4 | obj.a.b ||= c;
|
||||
5 |
|
||||
6 | a &&= b;"
|
||||
`;
|
||||
|
||||
exports[`logical-assignment-operators.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "babel-ts", "babel-flow"]
|
||||
@@ -845,15 +1051,33 @@ obj.a.b &&= c;
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`module-string-names.js [espree] format 1`] = `
|
||||
"Unexpected token \\"😄\\" (1:10)
|
||||
> 1 | import { \\"😄\\" as smile } from \\"./emojis.js\\";
|
||||
| ^
|
||||
2 | export { smile as \\"😄\\" } from \\"./emojis.js\\";
|
||||
3 | "
|
||||
`;
|
||||
|
||||
exports[`module-string-names.js [meriyah] format 1`] = `
|
||||
"[1:13]: Expected '}' (1:13)
|
||||
> 1 | import { \\"😄\\" as smile } from \\"./emojis.js\\";
|
||||
| ^
|
||||
2 | export { smile as \\"😄\\" } from \\"./emojis.js\\";
|
||||
3 | "
|
||||
`;
|
||||
|
||||
exports[`module-string-names.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "babel-ts", "babel-flow"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
import { "😄" as smile } from "./emojis.js";
|
||||
export { smile as "😄" } from "./emojis.js";
|
||||
|
||||
=====================================output=====================================
|
||||
import { "😄" as smile } from "./emojis.js";
|
||||
export { smile as "😄" } from "./emojis.js";
|
||||
|
||||
================================================================================
|
||||
@@ -1033,6 +1257,28 @@ try {
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`optional-chaining.js [espree] format 1`] = `
|
||||
"Optional chaining cannot appear in the callee of new expressions (56:21)
|
||||
54 | };
|
||||
55 |
|
||||
> 56 | const baz3 = new obj?.foo?.bar?.baz(); // baz instance
|
||||
| ^
|
||||
57 |
|
||||
58 | const safe5 = new obj?.qux?.baz(); // undefined
|
||||
59 | const safe6 = new obj?.foo.bar.qux?.(); // undefined"
|
||||
`;
|
||||
|
||||
exports[`optional-chaining.js [meriyah] format 1`] = `
|
||||
"[56:22]: Invalid optional chain from new expression (56:22)
|
||||
54 | };
|
||||
55 |
|
||||
> 56 | const baz3 = new obj?.foo?.bar?.baz(); // baz instance
|
||||
| ^
|
||||
57 |
|
||||
58 | const safe5 = new obj?.qux?.baz(); // undefined
|
||||
59 | const safe6 = new obj?.foo.bar.qux?.(); // undefined"
|
||||
`;
|
||||
|
||||
exports[`optional-chaining.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "babel-ts", "babel-flow"]
|
||||
@@ -1195,6 +1441,28 @@ const ret = delete obj?.foo?.bar?.baz; // true
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`partial-application.js [espree] format 1`] = `
|
||||
"Unexpected token ? (5:23)
|
||||
3 | function add(x, y) { return x + y; }
|
||||
4 |
|
||||
> 5 | const addOne = add(1, ?); // apply from the left
|
||||
| ^
|
||||
6 | addOne(2); // 3
|
||||
7 |
|
||||
8 | const addTen = add(?, 10); // apply from the right"
|
||||
`;
|
||||
|
||||
exports[`partial-application.js [meriyah] format 1`] = `
|
||||
"[5:23]: Unexpected token: '?' (5:23)
|
||||
3 | function add(x, y) { return x + y; }
|
||||
4 |
|
||||
> 5 | const addOne = add(1, ?); // apply from the left
|
||||
| ^
|
||||
6 | addOne(2); // 3
|
||||
7 |
|
||||
8 | const addTen = add(?, 10); // apply from the right"
|
||||
`;
|
||||
|
||||
exports[`partial-application.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "babel-ts", "babel-flow"]
|
||||
@@ -1249,6 +1517,28 @@ super.f(?); // partial application allowed for call on |SuperProperty|
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`pipeline-operator-fsharp.js [espree] format 1`] = `
|
||||
"Unexpected token > (5:4)
|
||||
3 |
|
||||
4 | promise
|
||||
> 5 | |> await
|
||||
| ^
|
||||
6 | |> x => doubleSay(x, ', ')
|
||||
7 | |> capitalize
|
||||
8 | |> x => x + '!'"
|
||||
`;
|
||||
|
||||
exports[`pipeline-operator-fsharp.js [meriyah] format 1`] = `
|
||||
"[5:4]: Unexpected token: '>' (5:4)
|
||||
3 |
|
||||
4 | promise
|
||||
> 5 | |> await
|
||||
| ^
|
||||
6 | |> x => doubleSay(x, ', ')
|
||||
7 | |> capitalize
|
||||
8 | |> x => x + '!'"
|
||||
`;
|
||||
|
||||
exports[`pipeline-operator-fsharp.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "babel-ts", "babel-flow"]
|
||||
@@ -1324,6 +1614,28 @@ let newScore = boundScore(0, 100, add(7, double(person.score)));
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`pipeline-operator-minimal.js [espree] format 1`] = `
|
||||
"Identifier 'result' has already been declared (7:5)
|
||||
5 | result //=> \\"Hello, hello!\\"
|
||||
6 |
|
||||
> 7 | let result = \\"hello\\"
|
||||
| ^
|
||||
8 | |> doubleSay
|
||||
9 | |> capitalize
|
||||
10 | |> exclaim;"
|
||||
`;
|
||||
|
||||
exports[`pipeline-operator-minimal.js [meriyah] format 1`] = `
|
||||
"[8:4]: Unexpected token: '>' (8:4)
|
||||
6 |
|
||||
7 | let result = \\"hello\\"
|
||||
> 8 | |> doubleSay
|
||||
| ^
|
||||
9 | |> capitalize
|
||||
10 | |> exclaim;
|
||||
11 | "
|
||||
`;
|
||||
|
||||
exports[`pipeline-operator-minimal.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "babel-ts", "babel-flow"]
|
||||
@@ -1357,6 +1669,28 @@ result; //=> "Hello, hello!"
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`pipeline-operator-smart.js [espree] format 1`] = `
|
||||
"Unexpected token > (5:2)
|
||||
3 |
|
||||
4 | value
|
||||
> 5 | |> await #
|
||||
| ^
|
||||
6 | |> doubleSay(#, ', ')
|
||||
7 | |> capitalize // This is a function call.
|
||||
8 | |> # + '!'"
|
||||
`;
|
||||
|
||||
exports[`pipeline-operator-smart.js [meriyah] format 1`] = `
|
||||
"[5:2]: Unexpected token: '>' (5:2)
|
||||
3 |
|
||||
4 | value
|
||||
> 5 | |> await #
|
||||
| ^
|
||||
6 | |> doubleSay(#, ', ')
|
||||
7 | |> capitalize // This is a function call.
|
||||
8 | |> # + '!'"
|
||||
`;
|
||||
|
||||
exports[`pipeline-operator-smart.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "babel-ts", "babel-flow"]
|
||||
@@ -1395,6 +1729,17 @@ value
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`private-fields-in-in.js [espree] format 1`] = `
|
||||
"Unexpected character '#' (4:3)
|
||||
2 |
|
||||
3 | class C {
|
||||
> 4 | #brand;
|
||||
| ^
|
||||
5 |
|
||||
6 | static isC(obj) {
|
||||
7 | try {"
|
||||
`;
|
||||
|
||||
exports[`private-fields-in-in.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "babel-ts", "babel-flow"]
|
||||
@@ -1517,6 +1862,17 @@ class C {
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`private-methods.js [espree] format 1`] = `
|
||||
"Unexpected character '#' (6:3)
|
||||
4 |
|
||||
5 | class Counter extends HTMLElement {
|
||||
> 6 | #xValue = 0;
|
||||
| ^
|
||||
7 |
|
||||
8 | get #x() { return this.#xValue; }
|
||||
9 | set #x(value) {"
|
||||
`;
|
||||
|
||||
exports[`private-methods.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "babel-ts", "babel-flow"]
|
||||
@@ -1566,6 +1922,24 @@ class Counter extends HTMLElement {
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`record-tuple-record.js [espree] format 1`] = `
|
||||
"Unexpected character '#' (1:17)
|
||||
> 1 | const record1 = #{
|
||||
| ^
|
||||
2 | a: 1,
|
||||
3 | b: 2,
|
||||
4 | c: 3,"
|
||||
`;
|
||||
|
||||
exports[`record-tuple-record.js [meriyah] format 1`] = `
|
||||
"[1:17]: '#' not followed by identifier (1:17)
|
||||
> 1 | const record1 = #{
|
||||
| ^
|
||||
2 | a: 1,
|
||||
3 | b: 2,
|
||||
4 | c: 3,"
|
||||
`;
|
||||
|
||||
exports[`record-tuple-record.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "babel-ts", "babel-flow"]
|
||||
@@ -1592,6 +1966,20 @@ const record2 = #{ ...record1, b: 5 };
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`record-tuple-tuple.js [espree] format 1`] = `
|
||||
"Unexpected character '#' (1:16)
|
||||
> 1 | const tuple1 = #[1, 2, 3];
|
||||
| ^
|
||||
2 | "
|
||||
`;
|
||||
|
||||
exports[`record-tuple-tuple.js [meriyah] format 1`] = `
|
||||
"[1:16]: '#' not followed by identifier (1:16)
|
||||
> 1 | const tuple1 = #[1, 2, 3];
|
||||
| ^
|
||||
2 | "
|
||||
`;
|
||||
|
||||
exports[`record-tuple-tuple.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "babel-ts", "babel-flow"]
|
||||
@@ -1606,6 +1994,28 @@ const tuple1 = #[1, 2, 3];
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`throw-expressions.js [espree] format 1`] = `
|
||||
"Unexpected token throw (3:23)
|
||||
1 | // https://babeljs.io/docs/en/babel-plugin-proposal-throw-expressions
|
||||
2 |
|
||||
> 3 | function test(param = throw new Error('required!')) {
|
||||
| ^
|
||||
4 | const test = param === true || throw new Error('Falsy!');
|
||||
5 | }
|
||||
6 | "
|
||||
`;
|
||||
|
||||
exports[`throw-expressions.js [meriyah] format 1`] = `
|
||||
"[3:27]: Unexpected token: 'throw' (3:27)
|
||||
1 | // https://babeljs.io/docs/en/babel-plugin-proposal-throw-expressions
|
||||
2 |
|
||||
> 3 | function test(param = throw new Error('required!')) {
|
||||
| ^
|
||||
4 | const test = param === true || throw new Error('Falsy!');
|
||||
5 | }
|
||||
6 | "
|
||||
`;
|
||||
|
||||
exports[`throw-expressions.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "babel-ts", "babel-flow"]
|
||||
@@ -1628,6 +2038,24 @@ function test(param = throw new Error("required!")) {
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`typescript.js [espree] format 1`] = `
|
||||
"Unexpected token : (3:8)
|
||||
1 | // https://babeljs.io/docs/en/babel-preset-typescript
|
||||
2 |
|
||||
> 3 | const x: number = 0;
|
||||
| ^
|
||||
4 | "
|
||||
`;
|
||||
|
||||
exports[`typescript.js [meriyah] format 1`] = `
|
||||
"[3:8]: Missing initializer in const declaration (3:8)
|
||||
1 | // https://babeljs.io/docs/en/babel-preset-typescript
|
||||
2 |
|
||||
> 3 | const x: number = 0;
|
||||
| ^
|
||||
4 | "
|
||||
`;
|
||||
|
||||
exports[`typescript.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "babel-ts", "babel-flow"]
|
||||
@@ -1646,6 +2074,28 @@ const x: number = 0;
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`v8intrinsic.js [espree] format 1`] = `
|
||||
"Unexpected token % (3:1)
|
||||
1 | // https://github.com/babel/babel/pull/10148
|
||||
2 |
|
||||
> 3 | %DebugPrint(foo);
|
||||
| ^
|
||||
4 |
|
||||
5 |
|
||||
6 | // Invalid code https://github.com/JLHwung/babel/blob/c1a3cbfd65e08b7013fd6f8c62add8cb10b4b169/packages/babel-parser/test/fixtures/v8intrinsic/_errors/in-bind-expression/options.json"
|
||||
`;
|
||||
|
||||
exports[`v8intrinsic.js [meriyah] format 1`] = `
|
||||
"[3:1]: Unexpected token: '%' (3:1)
|
||||
1 | // https://github.com/babel/babel/pull/10148
|
||||
2 |
|
||||
> 3 | %DebugPrint(foo);
|
||||
| ^
|
||||
4 |
|
||||
5 |
|
||||
6 | // Invalid code https://github.com/JLHwung/babel/blob/c1a3cbfd65e08b7013fd6f8c62add8cb10b4b169/packages/babel-parser/test/fixtures/v8intrinsic/_errors/in-bind-expression/options.json"
|
||||
`;
|
||||
|
||||
exports[`v8intrinsic.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "babel-ts", "babel-flow"]
|
||||
|
||||
@@ -29,5 +29,30 @@ run_spec(__dirname, ["babel", "babel-ts", "babel-flow"], {
|
||||
"module-string-names.js",
|
||||
"class-static-block.js",
|
||||
],
|
||||
meriyah: [
|
||||
"decimal.js",
|
||||
"do-expressions.js",
|
||||
"export-default-from.js",
|
||||
"flow.js",
|
||||
"function-bind.js",
|
||||
"function-sent.js",
|
||||
"logical-assignment-operators.js",
|
||||
"module-attributes-dynamic.js",
|
||||
"module-attributes-static.js",
|
||||
"partial-application.js",
|
||||
"pipeline-operator-fsharp.js",
|
||||
"pipeline-operator-minimal.js",
|
||||
"pipeline-operator-smart.js",
|
||||
"record-tuple-record.js",
|
||||
"record-tuple-tuple.js",
|
||||
"throw-expressions.js",
|
||||
"typescript.js",
|
||||
"v8intrinsic.js",
|
||||
"optional-chaining.js",
|
||||
"class-static-block.js",
|
||||
"import-assertions-dynamic.js",
|
||||
"import-assertions-static.js",
|
||||
"module-string-names.js",
|
||||
],
|
||||
},
|
||||
});
|
||||
@@ -1 +1,2 @@
|
||||
import { "😄" as smile } from "./emojis.js";
|
||||
export { smile as "😄" } from "./emojis.js";
|
||||
@@ -740,6 +740,27 @@ printWidth: 80
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`like-regexp.js [espree] format 1`] = `
|
||||
"Unterminated regular expression (1:19)
|
||||
> 1 | 0 ? a : { b : 1 }/2;
|
||||
| ^
|
||||
2 | "
|
||||
`;
|
||||
|
||||
exports[`like-regexp.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "flow", "typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
0 ? a : { b : 1 }/2;
|
||||
|
||||
=====================================output=====================================
|
||||
0 ? a : { b: 1 } / 2;
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`math.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "flow", "typescript"]
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
run_spec(__dirname, ["babel", "flow", "typescript"]);
|
||||
run_spec(__dirname, ["babel", "flow", "typescript"], {
|
||||
errors: { espree: ["like-regexp.js"] },
|
||||
});
|
||||
@@ -0,0 +1 @@
|
||||
0 ? a : { b : 1 }/2;
|
||||
@@ -1,5 +1,45 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`await.js [espree] format 1`] = `
|
||||
"Unexpected token : (3:27)
|
||||
1 | const doBothThings = async () => {
|
||||
2 | const request = doAsyncThing();
|
||||
> 3 | return (await request)::doSyncThing();
|
||||
| ^
|
||||
4 | };
|
||||
5 | "
|
||||
`;
|
||||
|
||||
exports[`await.js [meriyah] format 1`] = `
|
||||
"[3:27]: Unexpected token: ':' (3:27)
|
||||
1 | const doBothThings = async () => {
|
||||
2 | const request = doAsyncThing();
|
||||
> 3 | return (await request)::doSyncThing();
|
||||
| ^
|
||||
4 | };
|
||||
5 | "
|
||||
`;
|
||||
|
||||
exports[`await.js - {"semi":false} [espree] format 1`] = `
|
||||
"Unexpected token : (3:27)
|
||||
1 | const doBothThings = async () => {
|
||||
2 | const request = doAsyncThing();
|
||||
> 3 | return (await request)::doSyncThing();
|
||||
| ^
|
||||
4 | };
|
||||
5 | "
|
||||
`;
|
||||
|
||||
exports[`await.js - {"semi":false} [meriyah] format 1`] = `
|
||||
"[3:27]: Unexpected token: ':' (3:27)
|
||||
1 | const doBothThings = async () => {
|
||||
2 | const request = doAsyncThing();
|
||||
> 3 | return (await request)::doSyncThing();
|
||||
| ^
|
||||
4 | };
|
||||
5 | "
|
||||
`;
|
||||
|
||||
exports[`await.js - {"semi":false} format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
@@ -41,6 +81,42 @@ const doBothThings = async () => {
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`bind_parens.js [espree] format 1`] = `
|
||||
"Unexpected token : (1:9)
|
||||
> 1 | (a || b)::c;
|
||||
| ^
|
||||
2 | a || (b::c);
|
||||
3 | ::obj.prop;
|
||||
4 | (void 0)::func();"
|
||||
`;
|
||||
|
||||
exports[`bind_parens.js [meriyah] format 1`] = `
|
||||
"[1:9]: Unexpected token: ':' (1:9)
|
||||
> 1 | (a || b)::c;
|
||||
| ^
|
||||
2 | a || (b::c);
|
||||
3 | ::obj.prop;
|
||||
4 | (void 0)::func();"
|
||||
`;
|
||||
|
||||
exports[`bind_parens.js - {"semi":false} [espree] format 1`] = `
|
||||
"Unexpected token : (1:9)
|
||||
> 1 | (a || b)::c;
|
||||
| ^
|
||||
2 | a || (b::c);
|
||||
3 | ::obj.prop;
|
||||
4 | (void 0)::func();"
|
||||
`;
|
||||
|
||||
exports[`bind_parens.js - {"semi":false} [meriyah] format 1`] = `
|
||||
"[1:9]: Unexpected token: ':' (1:9)
|
||||
> 1 | (a || b)::c;
|
||||
| ^
|
||||
2 | a || (b::c);
|
||||
3 | ::obj.prop;
|
||||
4 | (void 0)::func();"
|
||||
`;
|
||||
|
||||
exports[`bind_parens.js - {"semi":false} format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
@@ -202,6 +278,50 @@ f[a::b()];
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`long_name_method.js [espree] format 1`] = `
|
||||
"Unexpected token : (3:54)
|
||||
1 | class X {
|
||||
2 | constructor() {
|
||||
> 3 | this.testLongNameMethodAndSomethingElseLallala = ::this.testLongNameMethodAndSomethingElseLallala;
|
||||
| ^
|
||||
4 | }
|
||||
5 |
|
||||
6 | testLongNameMethodAndSomethingElseLallala() {"
|
||||
`;
|
||||
|
||||
exports[`long_name_method.js [meriyah] format 1`] = `
|
||||
"[3:54]: Unexpected token: ':' (3:54)
|
||||
1 | class X {
|
||||
2 | constructor() {
|
||||
> 3 | this.testLongNameMethodAndSomethingElseLallala = ::this.testLongNameMethodAndSomethingElseLallala;
|
||||
| ^
|
||||
4 | }
|
||||
5 |
|
||||
6 | testLongNameMethodAndSomethingElseLallala() {"
|
||||
`;
|
||||
|
||||
exports[`long_name_method.js - {"semi":false} [espree] format 1`] = `
|
||||
"Unexpected token : (3:54)
|
||||
1 | class X {
|
||||
2 | constructor() {
|
||||
> 3 | this.testLongNameMethodAndSomethingElseLallala = ::this.testLongNameMethodAndSomethingElseLallala;
|
||||
| ^
|
||||
4 | }
|
||||
5 |
|
||||
6 | testLongNameMethodAndSomethingElseLallala() {"
|
||||
`;
|
||||
|
||||
exports[`long_name_method.js - {"semi":false} [meriyah] format 1`] = `
|
||||
"[3:54]: Unexpected token: ':' (3:54)
|
||||
1 | class X {
|
||||
2 | constructor() {
|
||||
> 3 | this.testLongNameMethodAndSomethingElseLallala = ::this.testLongNameMethodAndSomethingElseLallala;
|
||||
| ^
|
||||
4 | }
|
||||
5 |
|
||||
6 | testLongNameMethodAndSomethingElseLallala() {"
|
||||
`;
|
||||
|
||||
exports[`long_name_method.js - {"semi":false} format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
@@ -263,6 +383,50 @@ class X {
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`method_chain.js [espree] format 1`] = `
|
||||
"Unexpected token : (10:9)
|
||||
8 | function test(observable) {
|
||||
9 | return observable
|
||||
> 10 | ::filter(data => data.someTest)
|
||||
| ^
|
||||
11 | ::throttle(() =>
|
||||
12 | interval(10)
|
||||
13 | ::take(1)"
|
||||
`;
|
||||
|
||||
exports[`method_chain.js [meriyah] format 1`] = `
|
||||
"[10:9]: Unexpected token: ':' (10:9)
|
||||
8 | function test(observable) {
|
||||
9 | return observable
|
||||
> 10 | ::filter(data => data.someTest)
|
||||
| ^
|
||||
11 | ::throttle(() =>
|
||||
12 | interval(10)
|
||||
13 | ::take(1)"
|
||||
`;
|
||||
|
||||
exports[`method_chain.js - {"semi":false} [espree] format 1`] = `
|
||||
"Unexpected token : (10:9)
|
||||
8 | function test(observable) {
|
||||
9 | return observable
|
||||
> 10 | ::filter(data => data.someTest)
|
||||
| ^
|
||||
11 | ::throttle(() =>
|
||||
12 | interval(10)
|
||||
13 | ::take(1)"
|
||||
`;
|
||||
|
||||
exports[`method_chain.js - {"semi":false} [meriyah] format 1`] = `
|
||||
"[10:9]: Unexpected token: ':' (10:9)
|
||||
8 | function test(observable) {
|
||||
9 | return observable
|
||||
> 10 | ::filter(data => data.someTest)
|
||||
| ^
|
||||
11 | ::throttle(() =>
|
||||
12 | interval(10)
|
||||
13 | ::take(1)"
|
||||
`;
|
||||
|
||||
exports[`method_chain.js - {"semi":false} format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
@@ -356,6 +520,50 @@ function test(observable) {
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`short_name_method.js [espree] format 1`] = `
|
||||
"Unexpected token : (3:24)
|
||||
1 | class X {
|
||||
2 | constructor() {
|
||||
> 3 | this.shortMethod = ::this.shortMethod;
|
||||
| ^
|
||||
4 | }
|
||||
5 |
|
||||
6 | shortMethod() {"
|
||||
`;
|
||||
|
||||
exports[`short_name_method.js [meriyah] format 1`] = `
|
||||
"[3:24]: Unexpected token: ':' (3:24)
|
||||
1 | class X {
|
||||
2 | constructor() {
|
||||
> 3 | this.shortMethod = ::this.shortMethod;
|
||||
| ^
|
||||
4 | }
|
||||
5 |
|
||||
6 | shortMethod() {"
|
||||
`;
|
||||
|
||||
exports[`short_name_method.js - {"semi":false} [espree] format 1`] = `
|
||||
"Unexpected token : (3:24)
|
||||
1 | class X {
|
||||
2 | constructor() {
|
||||
> 3 | this.shortMethod = ::this.shortMethod;
|
||||
| ^
|
||||
4 | }
|
||||
5 |
|
||||
6 | shortMethod() {"
|
||||
`;
|
||||
|
||||
exports[`short_name_method.js - {"semi":false} [meriyah] format 1`] = `
|
||||
"[3:24]: Unexpected token: ':' (3:24)
|
||||
1 | class X {
|
||||
2 | constructor() {
|
||||
> 3 | this.shortMethod = ::this.shortMethod;
|
||||
| ^
|
||||
4 | }
|
||||
5 |
|
||||
6 | shortMethod() {"
|
||||
`;
|
||||
|
||||
exports[`short_name_method.js - {"semi":false} format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
@@ -415,6 +623,42 @@ class X {
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`unary.js [espree] format 1`] = `
|
||||
"Unexpected token : (1:3)
|
||||
> 1 | !x::y;
|
||||
| ^
|
||||
2 | !(x::y /* foo */);
|
||||
3 | !(/* foo */ x::y);
|
||||
4 | !("
|
||||
`;
|
||||
|
||||
exports[`unary.js [meriyah] format 1`] = `
|
||||
"[1:3]: Unexpected token: ':' (1:3)
|
||||
> 1 | !x::y;
|
||||
| ^
|
||||
2 | !(x::y /* foo */);
|
||||
3 | !(/* foo */ x::y);
|
||||
4 | !("
|
||||
`;
|
||||
|
||||
exports[`unary.js - {"semi":false} [espree] format 1`] = `
|
||||
"Unexpected token : (1:3)
|
||||
> 1 | !x::y;
|
||||
| ^
|
||||
2 | !(x::y /* foo */);
|
||||
3 | !(/* foo */ x::y);
|
||||
4 | !("
|
||||
`;
|
||||
|
||||
exports[`unary.js - {"semi":false} [meriyah] format 1`] = `
|
||||
"[1:3]: Unexpected token: ':' (1:3)
|
||||
> 1 | !x::y;
|
||||
| ^
|
||||
2 | !(x::y /* foo */);
|
||||
3 | !(/* foo */ x::y);
|
||||
4 | !("
|
||||
`;
|
||||
|
||||
exports[`unary.js - {"semi":false} format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
|
||||
@@ -1,2 +1,5 @@
|
||||
run_spec(__dirname, ["babel"], { errors: { espree: true } });
|
||||
run_spec(__dirname, ["babel"], { semi: false, errors: { espree: true } });
|
||||
run_spec(__dirname, ["babel"], { errors: { espree: true, meriyah: true } });
|
||||
run_spec(__dirname, ["babel"], {
|
||||
semi: false,
|
||||
errors: { espree: true, meriyah: true },
|
||||
});
|
||||
@@ -1,5 +1,15 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`class-property.js [espree] format 1`] = `
|
||||
"Unexpected token = (2:12)
|
||||
1 | class X {
|
||||
> 2 | TEMPLATE =
|
||||
| ^
|
||||
3 | // tab index is needed so we can focus, which is needed for keyboard events
|
||||
4 | '<div class=\\"ag-large-text\\" tabindex=\\"0\\">' +
|
||||
5 | '<div class=\\"ag-large-textarea\\"></div>' +"
|
||||
`;
|
||||
|
||||
exports[`class-property.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "flow", "typescript"]
|
||||
|
||||
@@ -1,5 +1,26 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`class-static-block.js [espree] format 1`] = `
|
||||
"Unexpected character '#' (2:10)
|
||||
1 | class C {
|
||||
> 2 | static #x = 42;
|
||||
| ^
|
||||
3 | static y;
|
||||
4 | static {
|
||||
5 | try {"
|
||||
`;
|
||||
|
||||
exports[`class-static-block.js [meriyah] format 1`] = `
|
||||
"[4:10]: Unexpected token: '{' (4:10)
|
||||
2 | static #x = 42;
|
||||
3 | static y;
|
||||
> 4 | static {
|
||||
| ^
|
||||
5 | try {
|
||||
6 | this.y = doSomethingWith(this.#x);
|
||||
7 | } catch {"
|
||||
`;
|
||||
|
||||
exports[`class-static-block.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
|
||||
@@ -1 +1 @@
|
||||
run_spec(__dirname, ["babel"], { errors: { espree: true } });
|
||||
run_spec(__dirname, ["babel"], { errors: { espree: true, meriyah: true } });
|
||||
@@ -1,5 +1,41 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`optional-chaining.js [espree] format 1`] = `
|
||||
"Unexpected character '#' (3:13)
|
||||
1 | // https://github.com/babel/babel/pull/11669
|
||||
2 |
|
||||
> 3 | delete obj?.#x.a
|
||||
| ^
|
||||
4 | "
|
||||
`;
|
||||
|
||||
exports[`optional-chaining.js [meriyah] format 1`] = `
|
||||
"[3:13]: Dot property must be an identifier (3:13)
|
||||
1 | // https://github.com/babel/babel/pull/11669
|
||||
2 |
|
||||
> 3 | delete obj?.#x.a
|
||||
| ^
|
||||
4 | "
|
||||
`;
|
||||
|
||||
exports[`optional-chaining.js - {"semi":false} [espree] format 1`] = `
|
||||
"Unexpected character '#' (3:13)
|
||||
1 | // https://github.com/babel/babel/pull/11669
|
||||
2 |
|
||||
> 3 | delete obj?.#x.a
|
||||
| ^
|
||||
4 | "
|
||||
`;
|
||||
|
||||
exports[`optional-chaining.js - {"semi":false} [meriyah] format 1`] = `
|
||||
"[3:13]: Dot property must be an identifier (3:13)
|
||||
1 | // https://github.com/babel/babel/pull/11669
|
||||
2 |
|
||||
> 3 | delete obj?.#x.a
|
||||
| ^
|
||||
4 | "
|
||||
`;
|
||||
|
||||
exports[`optional-chaining.js - {"semi":false} format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
@@ -37,6 +73,24 @@ delete obj?.#x.a;
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`private_fields.js [espree] format 1`] = `
|
||||
"Unexpected character '#' (1:11)
|
||||
> 1 | class A { #x; #y; }
|
||||
| ^
|
||||
2 | class B { #x = 0; #y = 1; }
|
||||
3 |
|
||||
4 | class C {"
|
||||
`;
|
||||
|
||||
exports[`private_fields.js - {"semi":false} [espree] format 1`] = `
|
||||
"Unexpected character '#' (1:11)
|
||||
> 1 | class A { #x; #y; }
|
||||
| ^
|
||||
2 | class B { #x = 0; #y = 1; }
|
||||
3 |
|
||||
4 | class C {"
|
||||
`;
|
||||
|
||||
exports[`private_fields.js - {"semi":false} format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
@@ -294,6 +348,26 @@ class F {
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`with_comments.js [espree] format 1`] = `
|
||||
"Unexpected character '#' (2:3)
|
||||
1 | class A {
|
||||
> 2 | #foobar =
|
||||
| ^
|
||||
3 | // comment to break
|
||||
4 | 1 +
|
||||
5 | // comment to break again"
|
||||
`;
|
||||
|
||||
exports[`with_comments.js - {"semi":false} [espree] format 1`] = `
|
||||
"Unexpected character '#' (2:3)
|
||||
1 | class A {
|
||||
> 2 | #foobar =
|
||||
| ^
|
||||
3 | // comment to break
|
||||
4 | 1 +
|
||||
5 | // comment to break again"
|
||||
`;
|
||||
|
||||
exports[`with_comments.js - {"semi":false} format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
|
||||
@@ -1,2 +1,7 @@
|
||||
run_spec(__dirname, ["babel"], { errors: { espree: true } });
|
||||
run_spec(__dirname, ["babel"], { semi: false, errors: { espree: true } });
|
||||
run_spec(__dirname, ["babel"], {
|
||||
errors: { espree: true, meriyah: ["optional-chaining.js"] },
|
||||
});
|
||||
run_spec(__dirname, ["babel"], {
|
||||
semi: false,
|
||||
errors: { espree: true, meriyah: ["optional-chaining.js"] },
|
||||
});
|
||||
@@ -202,6 +202,16 @@ new Ctor(class {});
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`property.js [espree] format 1`] = `
|
||||
"Unexpected token = (2:10)
|
||||
1 | class A {
|
||||
> 2 | foobar =
|
||||
| ^
|
||||
3 | // comment to break
|
||||
4 | 1 +
|
||||
5 | // comment to break again"
|
||||
`;
|
||||
|
||||
exports[`property.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "flow", "typescript"]
|
||||
|
||||
@@ -1,5 +1,19 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`example.js [espree] format 1`] = `
|
||||
"'super' keyword outside a method (1:1)
|
||||
> 1 | super();
|
||||
| ^
|
||||
2 | "
|
||||
`;
|
||||
|
||||
exports[`example.js [meriyah] format 1`] = `
|
||||
"[1:6]: Calls to super must be in the \\"constructor\\" method of a class expression or class declaration that has a superclass (1:6)
|
||||
> 1 | super();
|
||||
| ^
|
||||
2 | "
|
||||
`;
|
||||
|
||||
exports[`example.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "typescript"]
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
run_spec(__dirname, ["babel", "typescript"], { errors: { espree: true } });
|
||||
run_spec(__dirname, ["babel", "typescript"], {
|
||||
errors: { espree: true, meriyah: true },
|
||||
});
|
||||
@@ -1,5 +1,27 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`pipeline_own_line.js [espree] format 1`] = `
|
||||
"Unexpected token > (4:3)
|
||||
2 | 0
|
||||
3 | // Comment
|
||||
> 4 | |> x
|
||||
| ^
|
||||
5 | }
|
||||
6 |
|
||||
7 | bifornCringerMoshedPerplexSawder("
|
||||
`;
|
||||
|
||||
exports[`pipeline_own_line.js [meriyah] format 1`] = `
|
||||
"[4:3]: Unexpected token: '>' (4:3)
|
||||
2 | 0
|
||||
3 | // Comment
|
||||
> 4 | |> x
|
||||
| ^
|
||||
5 | }
|
||||
6 |
|
||||
7 | bifornCringerMoshedPerplexSawder("
|
||||
`;
|
||||
|
||||
exports[`pipeline_own_line.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
|
||||
@@ -1 +1 @@
|
||||
run_spec(__dirname, ["babel"], { errors: { espree: true } });
|
||||
run_spec(__dirname, ["babel"], { errors: { espree: true, meriyah: true } });
|
||||
@@ -0,0 +1,31 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`inline.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "flow", "typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
btnActions[1] = () => (
|
||||
<button> test </button>
|
||||
// :testC
|
||||
)
|
||||
|
||||
a(
|
||||
// ::
|
||||
1
|
||||
);
|
||||
|
||||
=====================================output=====================================
|
||||
btnActions[1] = () => (
|
||||
<button> test </button>
|
||||
// :testC
|
||||
);
|
||||
|
||||
a(
|
||||
// ::
|
||||
1
|
||||
);
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
@@ -0,0 +1,9 @@
|
||||
btnActions[1] = () => (
|
||||
<button> test </button>
|
||||
// :testC
|
||||
)
|
||||
|
||||
a(
|
||||
// ::
|
||||
1
|
||||
);
|
||||
@@ -0,0 +1 @@
|
||||
run_spec(__dirname, ["babel", "flow", "typescript"]);
|
||||
@@ -0,0 +1,18 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`comment.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["meriyah"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
<!--
|
||||
alert(1)
|
||||
-->
|
||||
=====================================output=====================================
|
||||
<!--
|
||||
alert(1);
|
||||
-->
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
@@ -0,0 +1,3 @@
|
||||
<!--
|
||||
alert(1)
|
||||
-->
|
||||
@@ -0,0 +1 @@
|
||||
run_spec(__dirname, ["meriyah"]);
|
||||
@@ -1,5 +1,25 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`comments.js [espree] format 1`] = `
|
||||
"Unexpected character '@' (2:5)
|
||||
1 | class Something {
|
||||
> 2 | @Annotateme()
|
||||
| ^
|
||||
3 | // comment
|
||||
4 | static property: Array<string>;
|
||||
5 | }"
|
||||
`;
|
||||
|
||||
exports[`comments.js [meriyah] format 1`] = `
|
||||
"[4:20]: Unexpected token: ':' (4:20)
|
||||
2 | @Annotateme()
|
||||
3 | // comment
|
||||
> 4 | static property: Array<string>;
|
||||
| ^
|
||||
5 | }
|
||||
6 | "
|
||||
`;
|
||||
|
||||
exports[`comments.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "typescript"]
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
run_spec(__dirname, ["babel", "typescript"], { errors: { espree: true } });
|
||||
run_spec(__dirname, ["babel", "typescript"], {
|
||||
errors: { espree: true, meriyah: true },
|
||||
});
|
||||
@@ -1,5 +1,23 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`after_export.js [espree] format 1`] = `
|
||||
"Unexpected character '@' (1:8)
|
||||
> 1 | export @decorator class Foo {}
|
||||
| ^
|
||||
2 |
|
||||
3 | export default @decorator class {}
|
||||
4 | "
|
||||
`;
|
||||
|
||||
exports[`after_export.js [meriyah] format 1`] = `
|
||||
"[1:8]: Unexpected token: '@' (1:8)
|
||||
> 1 | export @decorator class Foo {}
|
||||
| ^
|
||||
2 |
|
||||
3 | export default @decorator class {}
|
||||
4 | "
|
||||
`;
|
||||
|
||||
exports[`after_export.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
@@ -22,6 +40,15 @@ class {}
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`before_export.js [espree] format 1`] = `
|
||||
"Unexpected character '@' (1:1)
|
||||
> 1 | @decorator
|
||||
| ^
|
||||
2 | export class Foo {}
|
||||
3 |
|
||||
4 | @decorator"
|
||||
`;
|
||||
|
||||
exports[`before_export.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
// TypeScript and Flow don't accept decorator after export
|
||||
run_spec(__dirname, ["babel"], { errors: { espree: true } });
|
||||
run_spec(__dirname, ["babel"], {
|
||||
errors: { espree: true, meriyah: ["after_export.js"] },
|
||||
});
|
||||
@@ -1,5 +1,14 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`classes.js [espree] format 1`] = `
|
||||
"Unexpected character '@' (1:1)
|
||||
> 1 | @deco class Foo {}
|
||||
| ^
|
||||
2 |
|
||||
3 | @deco export class Bar {}
|
||||
4 | "
|
||||
`;
|
||||
|
||||
exports[`classes.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
@@ -47,6 +56,17 @@ const bar =
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`comments.js [espree] format 1`] = `
|
||||
"Unexpected character '@' (3:1)
|
||||
1 | var x = 100
|
||||
2 |
|
||||
> 3 | @Hello({
|
||||
| ^
|
||||
4 | a: 'a', // Comment is in the wrong place
|
||||
5 | // test
|
||||
6 | b: '2'"
|
||||
`;
|
||||
|
||||
exports[`comments.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
@@ -118,6 +138,17 @@ export class Bar {}
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`methods.js [espree] format 1`] = `
|
||||
"Unexpected character '@' (3:3)
|
||||
1 |
|
||||
2 | class Yo {
|
||||
> 3 | @foo(\\"hello\\")
|
||||
| ^
|
||||
4 | async plop() {}
|
||||
5 |
|
||||
6 | @anotherDecoratorWithALongName(\\"and a very long string as a first argument\\")"
|
||||
`;
|
||||
|
||||
exports[`methods.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
@@ -150,6 +181,17 @@ class Yo {
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`mixed.js [espree] format 1`] = `
|
||||
"Unexpected character '@' (3:1)
|
||||
1 | // https://github.com/prettier/prettier/issues/6747
|
||||
2 |
|
||||
> 3 | @foo
|
||||
| ^
|
||||
4 | export default class MyComponent {
|
||||
5 | @task
|
||||
6 | *foo() {"
|
||||
`;
|
||||
|
||||
exports[`mixed.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
@@ -176,6 +218,28 @@ export default class MyComponent {
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`mobx.js [espree] format 1`] = `
|
||||
"Unexpected character '@' (3:1)
|
||||
1 | import {observable} from \\"mobx\\";
|
||||
2 |
|
||||
> 3 | @observer class OrderLine {
|
||||
| ^
|
||||
4 | @observable price:number = 0;
|
||||
5 | @observable amount:number = 1;
|
||||
6 | "
|
||||
`;
|
||||
|
||||
exports[`mobx.js [meriyah] format 1`] = `
|
||||
"[4:20]: Unexpected token: ':' (4:20)
|
||||
2 |
|
||||
3 | @observer class OrderLine {
|
||||
> 4 | @observable price:number = 0;
|
||||
| ^
|
||||
5 | @observable amount:number = 1;
|
||||
6 |
|
||||
7 | constructor(price) {"
|
||||
`;
|
||||
|
||||
exports[`mobx.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
@@ -270,6 +334,16 @@ class OrderLine {
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`multiline.js [espree] format 1`] = `
|
||||
"Unexpected character '@' (2:3)
|
||||
1 | class Foo {
|
||||
> 2 | @deco([
|
||||
| ^
|
||||
3 | foo,
|
||||
4 | bar
|
||||
5 | ]) prop = value;"
|
||||
`;
|
||||
|
||||
exports[`multiline.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
@@ -292,6 +366,26 @@ class Foo {
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`multiple.js [espree] format 1`] = `
|
||||
"Unexpected character '@' (2:3)
|
||||
1 | const dog = {
|
||||
> 2 | @readonly
|
||||
| ^
|
||||
3 | @nonenumerable
|
||||
4 | @doubledValue
|
||||
5 | legs: 4,"
|
||||
`;
|
||||
|
||||
exports[`multiple.js [meriyah] format 1`] = `
|
||||
"[2:3]: Unexpected token: '@' (2:3)
|
||||
1 | const dog = {
|
||||
> 2 | @readonly
|
||||
| ^
|
||||
3 | @nonenumerable
|
||||
4 | @doubledValue
|
||||
5 | legs: 4,"
|
||||
`;
|
||||
|
||||
exports[`multiple.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
@@ -337,6 +431,16 @@ const foo = {
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`parens.js [espree] format 1`] = `
|
||||
"Unexpected character '@' (2:3)
|
||||
1 | class X {
|
||||
> 2 | @(computed().volatile())
|
||||
| ^
|
||||
3 | x
|
||||
4 | }
|
||||
5 | "
|
||||
`;
|
||||
|
||||
exports[`parens.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
@@ -357,6 +461,15 @@ class X {
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`redux.js [espree] format 1`] = `
|
||||
"Unexpected character '@' (1:1)
|
||||
> 1 | @connect(mapStateToProps, mapDispatchToProps)
|
||||
| ^
|
||||
2 | export class MyApp extends React.Component {}
|
||||
3 |
|
||||
4 | @connect(state => ({ todos: state.todos }))"
|
||||
`;
|
||||
|
||||
exports[`redux.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
run_spec(__dirname, ["babel"], { errors: { espree: true } });
|
||||
run_spec(__dirname, ["babel"], {
|
||||
errors: { espree: true, meriyah: ["multiple.js", "mobx.js"] },
|
||||
});
|
||||
@@ -1,5 +1,27 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`do.js [espree] format 1`] = `
|
||||
"Unexpected token do (3:5)
|
||||
1 | const envSpecific = {
|
||||
2 | domain:
|
||||
> 3 | do {
|
||||
| ^
|
||||
4 | if(env === 'production') 'https://abc.mno.com/';
|
||||
5 | else if(env === 'development') 'http://localhost:4000';
|
||||
6 | }"
|
||||
`;
|
||||
|
||||
exports[`do.js [meriyah] format 1`] = `
|
||||
"[3:6]: Unexpected token: 'do' (3:6)
|
||||
1 | const envSpecific = {
|
||||
2 | domain:
|
||||
> 3 | do {
|
||||
| ^
|
||||
4 | if(env === 'production') 'https://abc.mno.com/';
|
||||
5 | else if(env === 'development') 'http://localhost:4000';
|
||||
6 | }"
|
||||
`;
|
||||
|
||||
exports[`do.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
|
||||
@@ -1 +1 @@
|
||||
run_spec(__dirname, ["babel"], { errors: { espree: true } });
|
||||
run_spec(__dirname, ["babel"], { errors: { espree: true, meriyah: true } });
|
||||
Loaded 100 of 208 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user