Overhaul comment attachment (#13521)
* refactor: inline pushComment * chore: add benchmark cases * perf: overhaul comment attachment * cleanup * update test fixtures They are all bugfixes. * fix: merge HTMLComment parsing to skipSpace * perf: remove unattachedCommentStack baseline 128 nested leading comments: 11_034 ops/sec ±50.64% (0.091ms) baseline 256 nested leading comments: 6_037 ops/sec ±11.46% (0.166ms) baseline 512 nested leading comments: 3_077 ops/sec ±2.31% (0.325ms) baseline 1024 nested leading comments: 1_374 ops/sec ±3.22% (0.728ms) current 128 nested leading comments: 11_027 ops/sec ±37.41% (0.091ms) current 256 nested leading comments: 6_736 ops/sec ±1.39% (0.148ms) current 512 nested leading comments: 3_306 ops/sec ±0.69% (0.302ms) current 1024 nested leading comments: 1_579 ops/sec ±2.09% (0.633ms) baseline 128 nested trailing comments: 10_073 ops/sec ±42.95% (0.099ms) baseline 256 nested trailing comments: 6_294 ops/sec ±2.19% (0.159ms) baseline 512 nested trailing comments: 3_041 ops/sec ±0.8% (0.329ms) baseline 1024 nested trailing comments: 1_530 ops/sec ±1.18% (0.654ms) current 128 nested trailing comments: 11_461 ops/sec ±44.89% (0.087ms) current 256 nested trailing comments: 7_212 ops/sec ±1.6% (0.139ms) current 512 nested trailing comments: 3_403 ops/sec ±1% (0.294ms) current 1024 nested trailing comments: 1_539 ops/sec ±1.49% (0.65ms) * fix: do not expose CommentWhitespace type * add comments on CommentWhitespace * add test case for #11576 * fix: mark containerNode be the innermost node containing commentWS * fix: adjust trailing comma comments for Record/Tuple/OptionalCall * fix: drain comment stacks in parseExpression * docs: update comments * add a new benchmark * chore: containerNode => containingNode * add more benchmark cases * fix: avoid finishNodeAt in stmtToDirective * finalize comment right after containerNode is set * add testcase about directive * fix: finish SequenceExpression at current pos and adjust later * chore: rename test cases * add new test case on switch statement * fix: adjust comments after trailing comma of function params * add comment attachment design doc * misc fix * fix: reset previous trailing comments when parsing async method/accessor * chore: add more comment testcases * fix flow errors * fix: handle comments when parsing async arrow * fix: handle comments when "static" is a class modifier * fix flow errors * fix: handle comments when parsing async function/do * refactor: simplify resetPreviousNodeTrailingComments * update test fixtures
This commit is contained in:
parent
8a3e0fd960
commit
79d3276f61
129
packages/babel-parser/ast/comment-attachment.md
Normal file
129
packages/babel-parser/ast/comment-attachment.md
Normal file
@ -0,0 +1,129 @@
|
||||
# Comment attachment
|
||||
|
||||
When Babel is parsing JavaScript files, the comments will be attached to its adjacent AST nodes. If such neighbors do not exist, Babel will fallback to the innermost containing node.
|
||||
|
||||
The [current implementation](https://github.com/babel/babel/pull/13521) is based on its converse problem: Instead of attaching comments directly to AST nodes, we attach nodes to a stack of applicable comment whitespaces (see below for definitions). After a comment whitespace has set up its node relationship including leading, trailing and container, we forward the comments to the AST nodes and perform adjustments such as merge innerComments after trailing comma to the last element's trailing comments.
|
||||
|
||||
### Comment Whitespace
|
||||
|
||||
A comment whitespace represents a sequence of whitespace characters and comments including `//` comment line, `/* */` comment block, `<!--` HTML Open comment and `-->` HTML close comment. For example, the following snippet
|
||||
|
||||
```js
|
||||
a// 1
|
||||
/* 2 */
|
||||
+ <!-- 3
|
||||
-->
|
||||
2;
|
||||
```
|
||||
|
||||
have two comment whitespaces
|
||||
|
||||
```jsonc
|
||||
// for `// 1\n/* 2 */ `
|
||||
{
|
||||
start: 1, // position of '/'
|
||||
end: 15, // position of '+'
|
||||
comments: [
|
||||
CommentLine { start: 1, end: 5},
|
||||
CommentBlock { start: 6, end: 13 }
|
||||
],
|
||||
leadingNode: Identifier("a"),
|
||||
trailingNode: null,
|
||||
containerNode: BinaryExpression,
|
||||
}
|
||||
```
|
||||
|
||||
and
|
||||
|
||||
```jsonc
|
||||
// for ` <!-- 3\n-->\n`
|
||||
{
|
||||
start: 16, // position of ' ' after '+'
|
||||
end: 28, // position of '2'
|
||||
comments: [
|
||||
CommentLine { start: 17, end: 23},
|
||||
CommentLine { start: 24, end: 27 }
|
||||
],
|
||||
leadingNode: null,
|
||||
trailingNode: NumericLiteral(2),
|
||||
containerNode: BinaryExpression,
|
||||
}
|
||||
```
|
||||
|
||||
Given a program source, the set of all the comment whitespaces has the following properties:
|
||||
|
||||
**Nonemptiness** (P1): For every `w` of comment whitespaces, `w` satisifies
|
||||
|
||||
```
|
||||
w.start < w.end
|
||||
```
|
||||
|
||||
**Isolation** (P2): There must not exist any pair of comment whitespaces `w1` and `w2` such that
|
||||
|
||||
```
|
||||
w1.start ≤ w2.start ≤ w1.end
|
||||
```
|
||||
|
||||
**Completeness** (P3): For every comment AST node `c`, there must exist a comment whitespace `w`, such that
|
||||
|
||||
```
|
||||
w.start ≤ c.start < c.end ≤ w.end
|
||||
```
|
||||
|
||||
We can also say `w` encompasses `c`.
|
||||
|
||||
**Monotonicity** (Corollary from P1 and P2): Given a non-empty list of comment whitespaces orderred by `start`, denoted by `{ w1, w2, ... w_n }`, they must satisify
|
||||
|
||||
```
|
||||
w1.start < w1.end < w2.start < w2.end < ... < w_n.start < w_n.end
|
||||
```
|
||||
|
||||
For any given comment whitespace `w` and an AST node `n`, we can define the following relationships:
|
||||
|
||||
1. `n` is the _leading node_ of `w` iff `n.end = w.start`
|
||||
2. `n` is the _trailing node_ of `w` iff `n.start = w.end`
|
||||
3. `n` is the _containing node_ of `w` iff for all AST nodes `N` satisfying `N.start < w.start < w.end < N.end`, the following proposition is true:
|
||||
|
||||
```
|
||||
N.start ≤ n.start < w.start < w.end < n.end ≤ N.end
|
||||
```
|
||||
|
||||
Note that the relationship from `w` to `n` is _not_ injective. In other words, a comment whitespace can have multiple leading nodes, trailing nodes, and/or containing nodes. To address this issue we can define the extrema of the set of related ast nodes.
|
||||
|
||||
1. Outermost leading/trailing node: `n` is the _outermost leading/trailing node_ of `w` iff for every other leading/trailing node `N` of `w`, `N` is a descendant of `n`
|
||||
2. Innermost containing node: `n` is the _innermost containing node_ of `w` iff for every other containing node `N` of `w`, `n` is a descendant of `N`
|
||||
|
||||
For any given comment `c` and AST node `n`, now we can (in)formally define leading comments, trailing comments and inner comments:
|
||||
|
||||
**Leading Comment**: `c` is one of leading comments of `n` iff there exist a comment whitespace `w`, such that `n` is the outermost trailing node of `w` and `w` encompasses `c`
|
||||
|
||||
**Trailing Comment**: `c` is one of trailing comments of `n` iff there exist a comment whitespace `w`, such that `n` is the outermost leading node of `w` and `w` encompasses `c`
|
||||
|
||||
**Inner Comment**: `c` is one of inner comments of `n` iff
|
||||
|
||||
1. there exist a comment whitespace `w`, such that `n` is the innermost containing node of `w` and `w` encompasses `c`.
|
||||
2. there does not exist a comment whitespace `w`, such that `n` is the outermost leading or trailing node of `w and `w`encompasses`c`.
|
||||
|
||||
The Isolation (P2) of a comment whitespace gaurantees that if two comments `c1`, `c2` belongs to the leading/trailing comments of `n`, `c1` and `c2` must be encompassed by the same comment whitespace `w`. This property simplifies classification of leading/trailing because we can now mark a group of comments instead of checking every comments under the same comment whitespace.
|
||||
|
||||
Note that Babel parser marks certain inner comments after a trailing comma of a list structures to be the trailing comments of the last element in that list. (https://github.com/babel/babel/pull/10369) This behaviour can be considered as conpensation due to lack of a `TrailingCommaElement` AST structure to which a comment can be attached. Although this PR implements such behaviour, we will not be discussing it in the design section.
|
||||
|
||||
### Construct Comment Whitespace
|
||||
|
||||
We construct the comment whitespace in `Tokenizer#skipSpace` of `packages/babel-parser/src/tokenizer/index.js`, after we exit from the skip loop, we collect the `comments`, mark the location info and push to `parser.state.commentStack`. In this PR we also merge the parsing of `HTMLOpenComment` and `HTMLCloseComment` to `skipSpace`.
|
||||
|
||||
### Attaching Nodes to Comment Whitespace
|
||||
|
||||
For every finished AST node invoked from `parser#finishNode`. Before an AST node is finished, the whitespace token have been read from `tokenizer#next()`, so if this node has trailing comments, it must be the `leadingNode` of the last element in `commentStack`.
|
||||
|
||||
Note that the `leadingNode` will be updated by subsequent `finishNode()` calls invoked at the same position. The last `finishNode()` call is the winner, which is exactly the _outermost_ leading node that we are interested. Likewise for `trailingNode`.
|
||||
|
||||
Then we iterate `state.commentStack` reversely. we mark `trailingNode` when `comment.end = node.start`, mark `containingNode` when it is not defined, so here the first `finishNode()` is the winner, which is exactly the _innermost_ containing node.
|
||||
|
||||
After we set the containing node, we can assign comments to related node, since the nature of a recursive descending parser requires that when `containingNode` is finished, its `leadingNode` and `trailingNode` must have been parsed<sup>\*</sup>, so the related node stops being updated by `processComment`.
|
||||
|
||||
<sub>\* Technically this is not always true because we have `estree` plugins invokes `finishNodeAt` at a different tokenizer location. However, since most `estree` users are using `@babel/eslint-parser`, which removes the attached comment. So we are good here.</sub>
|
||||
|
||||
### Finalize comment whitespaces
|
||||
|
||||
In this step we attach the comments and do the trailing comma adjustments. Note that an extra routine `finalizeRemainingComments` is provided for `parseExpression`, which may not have opportunity to finalize comments which is added to the leading/trailing of the top level Expression node.
|
||||
22
packages/babel-parser/benchmark/many-async-arrows/bench.mjs
Normal file
22
packages/babel-parser/benchmark/many-async-arrows/bench.mjs
Normal file
@ -0,0 +1,22 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "../../lib/index.js";
|
||||
import { report } from "../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "async () => {};".repeat(length);
|
||||
}
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [256, 512, 1024, 2048]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} async arrow functions`, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@ -0,0 +1,22 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "../../lib/index.js";
|
||||
import { report } from "../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "[,\n// c\n".repeat(length) + "\n]".repeat(length);
|
||||
}
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [128, 256, 512, 1024]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} nested inner comments`, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@ -0,0 +1,24 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "../../lib/index.js";
|
||||
import { report } from "../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "[" + "// c\n".repeat(length) + "]";
|
||||
}
|
||||
current.parse(createInput(256), {});
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [128, 256, 512, 1024]) {
|
||||
const input = createInput(length);
|
||||
const { parse } = implementation;
|
||||
suite.add(`${name} ${length} inner comments`, () => {
|
||||
parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@ -0,0 +1,24 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "../../lib/index.js";
|
||||
import { report } from "../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "// c\n{\n".repeat(length) + "}".repeat(length);
|
||||
}
|
||||
current.parse(createInput(256), {});
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [128, 256, 512, 1024]) {
|
||||
const input = createInput(length);
|
||||
const { parse } = implementation;
|
||||
suite.add(`${name} ${length} nested leading comments`, () => {
|
||||
parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@ -0,0 +1,24 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "../../lib/index.js";
|
||||
import { report } from "../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "// c\n".repeat(length) + "{}";
|
||||
}
|
||||
current.parse(createInput(256), {});
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [128, 256, 512, 1024]) {
|
||||
const input = createInput(length);
|
||||
const { parse } = implementation;
|
||||
suite.add(`${name} ${length} leading comments`, () => {
|
||||
parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@ -0,0 +1,27 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "../../lib/index.js";
|
||||
import { report } from "../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "\n// c\na".repeat(length);
|
||||
}
|
||||
current.parse(createInput(256), {});
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [128, 256, 512, 1024]) {
|
||||
const input = createInput(length);
|
||||
const { parse } = implementation;
|
||||
suite.add(
|
||||
`${name} ${length} leading comments + ${length - 1} trailing comments`,
|
||||
() => {
|
||||
parse(input, options);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@ -0,0 +1,22 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "../../lib/index.js";
|
||||
import { report } from "../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "{".repeat(length) + "} // c\n".repeat(length);
|
||||
}
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [128, 256, 512, 1024]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} nested trailing comments`, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@ -0,0 +1,24 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "../../lib/index.js";
|
||||
import { report } from "../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "{}" + "// c\n".repeat(length);
|
||||
}
|
||||
current.parse(createInput(256), {});
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [128, 256, 512, 1024]) {
|
||||
const input = createInput(length);
|
||||
const { parse } = implementation;
|
||||
suite.add(`${name} ${length} trailing comments`, () => {
|
||||
parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@ -1,288 +1,241 @@
|
||||
// @flow
|
||||
|
||||
/**
|
||||
* Based on the comment attachment algorithm used in espree and estraverse.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*:: declare var invariant; */
|
||||
|
||||
import BaseParser from "./base";
|
||||
import type { Comment, Node } from "../types";
|
||||
import * as charCodes from "charcodes";
|
||||
|
||||
function last<T>(stack: $ReadOnlyArray<T>): T {
|
||||
return stack[stack.length - 1];
|
||||
/**
|
||||
* A whitespace token containing comments
|
||||
* @typedef CommentWhitespace
|
||||
* @type {object}
|
||||
* @property {number} start - the start of the whitespace token.
|
||||
* @property {number} end - the end of the whitespace token.
|
||||
* @property {Array<Comment>} comments - the containing comments
|
||||
* @property {Node | null} leadingNode - the immediately preceding AST node of the whitespace token
|
||||
* @property {Node | null} trailingNode - the immediately following AST node of the whitespace token
|
||||
* @property {Node | null} containingNode - the innermost AST node containing the whitespace
|
||||
* with minimal size (|end - start|)
|
||||
*/
|
||||
export type CommentWhitespace = {
|
||||
start: number,
|
||||
end: number,
|
||||
comments: Array<Comment>,
|
||||
leadingNode: Node | null,
|
||||
trailingNode: Node | null,
|
||||
containingNode: Node | null,
|
||||
};
|
||||
/**
|
||||
* Merge comments with node's trailingComments or assign comments to be
|
||||
* trailingComments. New comments will be placed before old comments
|
||||
* because the commentStack is enumerated reversely.
|
||||
*
|
||||
* @param {Node} node
|
||||
* @param {Array<Comment>} comments
|
||||
*/
|
||||
function setTrailingComments(node: Node, comments: Array<Comment>) {
|
||||
if (node.trailingComments === undefined) {
|
||||
node.trailingComments = comments;
|
||||
} else {
|
||||
node.trailingComments.unshift(...comments);
|
||||
}
|
||||
}
|
||||
|
||||
export default class CommentsParser extends BaseParser {
|
||||
addComment(comment: Comment): void {
|
||||
if (this.filename) comment.loc.filename = this.filename;
|
||||
this.state.trailingComments.push(comment);
|
||||
this.state.leadingComments.push(comment);
|
||||
/**
|
||||
* Merge comments with node's innerComments or assign comments to be
|
||||
* innerComments. New comments will be placed before old comments
|
||||
* because the commentStack is enumerated reversely.
|
||||
*
|
||||
* @param {Node} node
|
||||
* @param {Array<Comment>} comments
|
||||
*/
|
||||
export function setInnerComments(node: Node, comments: Array<Comment> | void) {
|
||||
if (node.innerComments === undefined) {
|
||||
node.innerComments = comments;
|
||||
} else if (comments !== undefined) {
|
||||
node.innerComments.unshift(...comments);
|
||||
}
|
||||
}
|
||||
|
||||
adjustCommentsAfterTrailingComma(
|
||||
/**
|
||||
* Given node and elements array, if elements has non-null element,
|
||||
* merge comments to its trailingComments, otherwise merge comments
|
||||
* to node's innerComments
|
||||
*
|
||||
* @param {Node} node
|
||||
* @param {Array<Node>} elements
|
||||
* @param {Array<Comment>} comments
|
||||
*/
|
||||
function adjustInnerComments(
|
||||
node: Node,
|
||||
elements: (Node | null)[],
|
||||
// When the current node is followed by a token which hasn't a respective AST node, we
|
||||
// need to take all the trailing comments to prevent them from being attached to an
|
||||
// unrelated node. e.g. in
|
||||
// var { x } /* cmt */ = { y }
|
||||
// we don't want /* cmt */ to be attached to { y }.
|
||||
// On the other hand, in
|
||||
// fn(x) [new line] /* cmt */ [new line] y
|
||||
// /* cmt */ is both a trailing comment of fn(x) and a leading comment of y
|
||||
takeAllComments?: boolean,
|
||||
) {
|
||||
if (this.state.leadingComments.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
elements: Array<Node>,
|
||||
commentWS: CommentWhitespace,
|
||||
) {
|
||||
let lastElement = null;
|
||||
let i = elements.length;
|
||||
while (lastElement === null && i > 0) {
|
||||
lastElement = elements[--i];
|
||||
}
|
||||
if (lastElement === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (let j = 0; j < this.state.leadingComments.length; j++) {
|
||||
if (
|
||||
this.state.leadingComments[j].end < this.state.commentPreviousNode.end
|
||||
) {
|
||||
this.state.leadingComments.splice(j, 1);
|
||||
j--;
|
||||
}
|
||||
}
|
||||
|
||||
const newTrailingComments = [];
|
||||
for (let i = 0; i < this.state.leadingComments.length; i++) {
|
||||
const leadingComment = this.state.leadingComments[i];
|
||||
if (leadingComment.end < node.end) {
|
||||
newTrailingComments.push(leadingComment);
|
||||
|
||||
// Perf: we don't need to splice if we are going to reset the array anyway
|
||||
if (!takeAllComments) {
|
||||
this.state.leadingComments.splice(i, 1);
|
||||
i--;
|
||||
}
|
||||
if (lastElement === null || lastElement.start > commentWS.start) {
|
||||
setInnerComments(node, commentWS.comments);
|
||||
} else {
|
||||
if (node.trailingComments === undefined) {
|
||||
node.trailingComments = [];
|
||||
}
|
||||
node.trailingComments.push(leadingComment);
|
||||
}
|
||||
}
|
||||
if (takeAllComments) this.state.leadingComments = [];
|
||||
|
||||
if (newTrailingComments.length > 0) {
|
||||
lastElement.trailingComments = newTrailingComments;
|
||||
} else if (lastElement.trailingComments !== undefined) {
|
||||
lastElement.trailingComments = [];
|
||||
}
|
||||
}
|
||||
|
||||
processComment(node: Node): void {
|
||||
if (node.type === "Program" && node.body.length > 0) return;
|
||||
|
||||
const stack = this.state.commentStack;
|
||||
|
||||
let firstChild, lastChild, trailingComments, i, j;
|
||||
|
||||
if (this.state.trailingComments.length > 0) {
|
||||
// If the first comment in trailingComments comes after the
|
||||
// current node, then we're good - all comments in the array will
|
||||
// come after the node and so it's safe to add them as official
|
||||
// trailingComments.
|
||||
if (this.state.trailingComments[0].start >= node.end) {
|
||||
trailingComments = this.state.trailingComments;
|
||||
this.state.trailingComments = [];
|
||||
} else {
|
||||
// Otherwise, if the first comment doesn't come after the
|
||||
// current node, that means we have a mix of leading and trailing
|
||||
// comments in the array and that leadingComments contains the
|
||||
// same items as trailingComments. Reset trailingComments to
|
||||
// zero items and we'll handle this by evaluating leadingComments
|
||||
// later.
|
||||
this.state.trailingComments.length = 0;
|
||||
}
|
||||
} else if (stack.length > 0) {
|
||||
const lastInStack = last(stack);
|
||||
if (
|
||||
lastInStack.trailingComments &&
|
||||
lastInStack.trailingComments[0].start >= node.end
|
||||
) {
|
||||
trailingComments = lastInStack.trailingComments;
|
||||
delete lastInStack.trailingComments;
|
||||
}
|
||||
}
|
||||
|
||||
// Eating the stack.
|
||||
if (stack.length > 0 && last(stack).start >= node.start) {
|
||||
firstChild = stack.pop();
|
||||
}
|
||||
|
||||
while (stack.length > 0 && last(stack).start >= node.start) {
|
||||
lastChild = stack.pop();
|
||||
}
|
||||
|
||||
if (!lastChild && firstChild) lastChild = firstChild;
|
||||
|
||||
// Adjust comments that follow a trailing comma on the last element in a
|
||||
// comma separated list of nodes to be the trailing comments on the last
|
||||
// element
|
||||
if (firstChild) {
|
||||
switch (node.type) {
|
||||
case "ObjectExpression":
|
||||
this.adjustCommentsAfterTrailingComma(node, node.properties);
|
||||
break;
|
||||
case "ObjectPattern":
|
||||
this.adjustCommentsAfterTrailingComma(node, node.properties, true);
|
||||
break;
|
||||
case "CallExpression":
|
||||
this.adjustCommentsAfterTrailingComma(node, node.arguments);
|
||||
break;
|
||||
case "ArrayExpression":
|
||||
this.adjustCommentsAfterTrailingComma(node, node.elements);
|
||||
break;
|
||||
case "ArrayPattern":
|
||||
this.adjustCommentsAfterTrailingComma(node, node.elements, true);
|
||||
break;
|
||||
}
|
||||
} else if (
|
||||
this.state.commentPreviousNode &&
|
||||
((this.state.commentPreviousNode.type === "ImportSpecifier" &&
|
||||
node.type !== "ImportSpecifier") ||
|
||||
(this.state.commentPreviousNode.type === "ExportSpecifier" &&
|
||||
node.type !== "ExportSpecifier"))
|
||||
) {
|
||||
this.adjustCommentsAfterTrailingComma(node, [
|
||||
this.state.commentPreviousNode,
|
||||
]);
|
||||
}
|
||||
|
||||
if (lastChild) {
|
||||
if (lastChild.leadingComments) {
|
||||
if (
|
||||
lastChild !== node &&
|
||||
lastChild.leadingComments.length > 0 &&
|
||||
last(lastChild.leadingComments).end <= node.start
|
||||
) {
|
||||
node.leadingComments = lastChild.leadingComments;
|
||||
delete lastChild.leadingComments;
|
||||
} else {
|
||||
// A leading comment for an anonymous class had been stolen by its first ClassMethod,
|
||||
// so this takes back the leading comment.
|
||||
// See also: https://github.com/eslint/espree/issues/158
|
||||
for (i = lastChild.leadingComments.length - 2; i >= 0; --i) {
|
||||
if (lastChild.leadingComments[i].end <= node.start) {
|
||||
node.leadingComments = lastChild.leadingComments.splice(0, i + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (this.state.leadingComments.length > 0) {
|
||||
if (last(this.state.leadingComments).end <= node.start) {
|
||||
if (this.state.commentPreviousNode) {
|
||||
for (j = 0; j < this.state.leadingComments.length; j++) {
|
||||
if (
|
||||
this.state.leadingComments[j].end <
|
||||
this.state.commentPreviousNode.end
|
||||
) {
|
||||
this.state.leadingComments.splice(j, 1);
|
||||
j--;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.state.leadingComments.length > 0) {
|
||||
node.leadingComments = this.state.leadingComments;
|
||||
this.state.leadingComments = [];
|
||||
}
|
||||
} else {
|
||||
// https://github.com/eslint/espree/issues/2
|
||||
//
|
||||
// In special cases, such as return (without a value) and
|
||||
// debugger, all comments will end up as leadingComments and
|
||||
// will otherwise be eliminated. This step runs when the
|
||||
// commentStack is empty and there are comments left
|
||||
// in leadingComments.
|
||||
//
|
||||
// This loop figures out the stopping point between the actual
|
||||
// leading and trailing comments by finding the location of the
|
||||
// first comment that comes after the given node.
|
||||
for (i = 0; i < this.state.leadingComments.length; i++) {
|
||||
if (this.state.leadingComments[i].end > node.start) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Split the array based on the location of the first comment
|
||||
// that comes after the node. Keep in mind that this could
|
||||
// result in an empty array, and if so, the array must be
|
||||
// deleted.
|
||||
const leadingComments = this.state.leadingComments.slice(0, i);
|
||||
|
||||
if (leadingComments.length) {
|
||||
node.leadingComments = leadingComments;
|
||||
}
|
||||
|
||||
// Similarly, trailing comments are attached later. The variable
|
||||
// must be reset to null if there are no trailing comments.
|
||||
trailingComments = this.state.leadingComments.slice(i);
|
||||
if (trailingComments.length === 0) {
|
||||
trailingComments = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.state.commentPreviousNode = node;
|
||||
|
||||
if (trailingComments) {
|
||||
if (
|
||||
trailingComments.length &&
|
||||
trailingComments[0].start >= node.start &&
|
||||
last(trailingComments).end <= node.end
|
||||
) {
|
||||
node.innerComments = trailingComments;
|
||||
} else {
|
||||
// TrailingComments maybe contain innerComments
|
||||
const firstTrailingCommentIndex = trailingComments.findIndex(
|
||||
comment => comment.end >= node.end,
|
||||
);
|
||||
|
||||
if (firstTrailingCommentIndex > 0) {
|
||||
node.innerComments = trailingComments.slice(
|
||||
0,
|
||||
firstTrailingCommentIndex,
|
||||
);
|
||||
node.trailingComments = trailingComments.slice(
|
||||
firstTrailingCommentIndex,
|
||||
);
|
||||
} else {
|
||||
node.trailingComments = trailingComments;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stack.push(node);
|
||||
setTrailingComments(lastElement, commentWS.comments);
|
||||
}
|
||||
}
|
||||
|
||||
/** @class CommentsParser */
|
||||
export default class CommentsParser extends BaseParser {
|
||||
addComment(comment: Comment): void {
|
||||
if (this.filename) comment.loc.filename = this.filename;
|
||||
this.state.comments.push(comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a newly created AST node _n_, attach _n_ to a comment whitespace _w_ if applicable
|
||||
* {@see {@link CommentWhitespace}}
|
||||
*
|
||||
* @param {Node} node
|
||||
* @returns {void}
|
||||
* @memberof CommentsParser
|
||||
*/
|
||||
processComment(node: Node): void {
|
||||
const { commentStack } = this.state;
|
||||
const commentStackLength = commentStack.length;
|
||||
if (commentStackLength === 0) return;
|
||||
let i = commentStackLength - 1;
|
||||
const lastCommentWS = commentStack[i];
|
||||
|
||||
if (lastCommentWS.start === node.end) {
|
||||
lastCommentWS.leadingNode = node;
|
||||
i--;
|
||||
}
|
||||
|
||||
const { start: nodeStart } = node;
|
||||
// invariant: for all 0 <= j <= i, let c = commentStack[j], c must satisfy c.end < node.end
|
||||
for (; i >= 0; i--) {
|
||||
const commentWS = commentStack[i];
|
||||
const commentEnd = commentWS.end;
|
||||
if (commentEnd > nodeStart) {
|
||||
// by definition of commentWhiteSpace, this implies commentWS.start > nodeStart
|
||||
// so node can be a containingNode candidate. At this time we can finalize the comment
|
||||
// whitespace, because
|
||||
// 1) its leadingNode or trailingNode, if exists, will not change
|
||||
// 2) its containingNode have been assigned and will not change because it is the
|
||||
// innermost minimal-sized AST node
|
||||
commentWS.containingNode = node;
|
||||
this.finalizeComment(commentWS);
|
||||
commentStack.splice(i, 1);
|
||||
} else {
|
||||
if (commentEnd === nodeStart) {
|
||||
commentWS.trailingNode = node;
|
||||
}
|
||||
// stop the loop when commentEnd <= nodeStart
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign the comments of comment whitespaces to related AST nodes.
|
||||
* Also adjust innerComments following trailing comma.
|
||||
*
|
||||
* @memberof CommentsParser
|
||||
*/
|
||||
finalizeComment(commentWS: CommentWhitespace) {
|
||||
const { comments } = commentWS;
|
||||
if (commentWS.leadingNode !== null || commentWS.trailingNode !== null) {
|
||||
if (commentWS.leadingNode !== null) {
|
||||
setTrailingComments(commentWS.leadingNode, comments);
|
||||
}
|
||||
if (commentWS.trailingNode !== null) {
|
||||
commentWS.trailingNode.leadingComments = comments;
|
||||
}
|
||||
} else {
|
||||
/*:: invariant(commentWS.containingNode !== null) */
|
||||
const { containingNode: node, start: commentStart } = commentWS;
|
||||
if (this.input.charCodeAt(commentStart - 1) === charCodes.comma) {
|
||||
// If a commentWhitespace follows a comma and the containingNode allows
|
||||
// list structures with trailing comma, merge it to the trailingComment
|
||||
// of the last non-null list element
|
||||
switch (node.type) {
|
||||
case "ObjectExpression":
|
||||
case "ObjectPattern":
|
||||
case "RecordExpression":
|
||||
adjustInnerComments(node, node.properties, commentWS);
|
||||
break;
|
||||
case "CallExpression":
|
||||
case "OptionalCallExpression":
|
||||
adjustInnerComments(node, node.arguments, commentWS);
|
||||
break;
|
||||
case "FunctionDeclaration":
|
||||
case "FunctionExpression":
|
||||
case "ArrowFunctionExpression":
|
||||
case "ObjectMethod":
|
||||
case "ClassMethod":
|
||||
case "ClassPrivateMethod":
|
||||
adjustInnerComments(node, node.params, commentWS);
|
||||
break;
|
||||
case "ArrayExpression":
|
||||
case "ArrayPattern":
|
||||
case "TupleExpression":
|
||||
adjustInnerComments(node, node.elements, commentWS);
|
||||
break;
|
||||
case "ExportNamedDeclaration":
|
||||
case "ImportDeclaration":
|
||||
adjustInnerComments(node, node.specifiers, commentWS);
|
||||
break;
|
||||
default: {
|
||||
setInnerComments(node, comments);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
setInnerComments(node, comments);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Drains remaning commentStack and applies finalizeComment
|
||||
* to each comment whitespace. Used only in parseExpression
|
||||
* where the top level AST node is _not_ Program
|
||||
* {@see {@link CommentsParser#finalizeComment}}
|
||||
*
|
||||
* @memberof CommentsParser
|
||||
*/
|
||||
finalizeRemainingComments() {
|
||||
const { commentStack } = this.state;
|
||||
for (let i = commentStack.length - 1; i >= 0; i--) {
|
||||
this.finalizeComment(commentStack[i]);
|
||||
}
|
||||
this.state.commentStack = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset previous node trailing comments. Used in object / class
|
||||
* property parsing. We parse `async`, `static`, `set` and `get`
|
||||
* as an identifier but may reinterepret it into an async/static/accessor
|
||||
* method later. In this case the identifier is not part of the AST and we
|
||||
* should sync the knowledge to commentStacks
|
||||
*
|
||||
* For example, when parsing */
|
||||
// async /* 1 */ function f() {}
|
||||
/*
|
||||
* the comment whitespace "* 1 *" has leading node Identifier(async). When
|
||||
* we see the function token, we create a Function node and mark "* 1 *" as
|
||||
* inner comments. So "* 1 *" should be detached from the Identifier node.
|
||||
*
|
||||
* @param {N.Node} node the last finished AST node _before_ current token
|
||||
* @returns
|
||||
* @memberof CommentsParser
|
||||
*/
|
||||
resetPreviousNodeTrailingComments(node: Node) {
|
||||
const { commentStack } = this.state;
|
||||
const { length } = commentStack;
|
||||
if (length === 0) return;
|
||||
const commentWS = commentStack[length - 1];
|
||||
if (commentWS.leadingNode === node) {
|
||||
commentWS.leadingNode = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,6 +56,7 @@ import {
|
||||
} from "../util/expression-scope";
|
||||
import { Errors, SourceTypeModuleErrors } from "./error";
|
||||
import type { ParsingError } from "./error";
|
||||
import { setInnerComments } from "./comments";
|
||||
|
||||
/*::
|
||||
import type { SourceType } from "../options";
|
||||
@ -161,6 +162,9 @@ export default class ExpressionParser extends LValParser {
|
||||
if (!this.match(tt.eof)) {
|
||||
this.unexpected();
|
||||
}
|
||||
// Unlike parseTopLevel, we need to drain remaining commentStacks
|
||||
// because the top level node is _not_ Program.
|
||||
this.finalizeRemainingComments();
|
||||
expr.comments = this.state.comments;
|
||||
expr.errors = this.state.errors;
|
||||
if (this.options.tokens) {
|
||||
@ -938,6 +942,7 @@ export default class ExpressionParser extends LValParser {
|
||||
node: N.ArrowFunctionExpression,
|
||||
call: N.CallExpression,
|
||||
): N.ArrowFunctionExpression {
|
||||
this.resetPreviousNodeTrailingComments(call);
|
||||
this.expect(tt.arrow);
|
||||
this.parseArrowExpression(
|
||||
node,
|
||||
@ -945,6 +950,10 @@ export default class ExpressionParser extends LValParser {
|
||||
true,
|
||||
call.extra?.trailingComma,
|
||||
);
|
||||
// mark inner comments of `async()` as inner comments of `async () =>`
|
||||
setInnerComments(node, call.innerComments);
|
||||
// mark trailing comments of `async` to be inner comments
|
||||
setInnerComments(node, call.callee.trailingComments);
|
||||
return node;
|
||||
}
|
||||
|
||||
@ -999,6 +1008,7 @@ export default class ExpressionParser extends LValParser {
|
||||
|
||||
if (!containsEsc && id.name === "async" && !this.canInsertSemicolon()) {
|
||||
if (this.match(tt._function)) {
|
||||
this.resetPreviousNodeTrailingComments(id);
|
||||
this.next();
|
||||
return this.parseFunction(
|
||||
this.startNodeAtNode(id),
|
||||
@ -1010,13 +1020,19 @@ export default class ExpressionParser extends LValParser {
|
||||
// arrow function. (Peeking ahead for "=" lets us avoid a more
|
||||
// expensive full-token lookahead on this common path.)
|
||||
if (this.lookaheadCharCode() === charCodes.equalsTo) {
|
||||
return this.parseAsyncArrowUnaryFunction(id);
|
||||
// although `id` is not used in async arrow unary function,
|
||||
// we don't need to reset `async`'s trailing comments because
|
||||
// it will be attached to the upcoming async arrow binding identifier
|
||||
return this.parseAsyncArrowUnaryFunction(
|
||||
this.startNodeAtNode(id),
|
||||
);
|
||||
} else {
|
||||
// Otherwise, treat "async" as an identifier and let calling code
|
||||
// deal with the current tt.name token.
|
||||
return id;
|
||||
}
|
||||
} else if (this.match(tt._do)) {
|
||||
this.resetPreviousNodeTrailingComments(id);
|
||||
return this.parseDo(this.startNodeAtNode(id), true);
|
||||
}
|
||||
}
|
||||
@ -1189,8 +1205,7 @@ export default class ExpressionParser extends LValParser {
|
||||
}
|
||||
|
||||
// async [no LineTerminator here] AsyncArrowBindingIdentifier[?Yield] [no LineTerminator here] => AsyncConciseBody[?In]
|
||||
parseAsyncArrowUnaryFunction(id: N.Expression): N.ArrowFunctionExpression {
|
||||
const node = this.startNodeAtNode(id);
|
||||
parseAsyncArrowUnaryFunction(node: N.Node): N.ArrowFunctionExpression {
|
||||
// We don't need to push a new ParameterDeclarationScope here since we are sure
|
||||
// 1) it is an async arrow, 2) no biding pattern is allowed in params
|
||||
this.prodParam.enter(functionFlags(true, this.prodParam.hasYield));
|
||||
@ -1509,7 +1524,10 @@ export default class ExpressionParser extends LValParser {
|
||||
if (exprList.length > 1) {
|
||||
val = this.startNodeAt(innerStartPos, innerStartLoc);
|
||||
val.expressions = exprList;
|
||||
this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
|
||||
// finish node at current location so it can pick up comments after `)`
|
||||
this.finishNode(val, "SequenceExpression");
|
||||
val.end = innerEndPos;
|
||||
val.loc.end = innerEndLoc;
|
||||
} else {
|
||||
val = exprList[0];
|
||||
}
|
||||
@ -1782,6 +1800,7 @@ export default class ExpressionParser extends LValParser {
|
||||
// https://tc39.es/ecma262/#prod-AsyncGeneratorMethod
|
||||
if (keyName === "async" && !this.hasPrecedingLineBreak()) {
|
||||
isAsync = true;
|
||||
this.resetPreviousNodeTrailingComments(key);
|
||||
isGenerator = this.eat(tt.star);
|
||||
this.parsePropertyName(prop, /* isPrivateNameAllowed */ false);
|
||||
}
|
||||
@ -1789,6 +1808,7 @@ export default class ExpressionParser extends LValParser {
|
||||
// set PropertyName[?Yield, ?Await] ( PropertySetParameterList ) { FunctionBody[~Yield, ~Await] }
|
||||
if (keyName === "get" || keyName === "set") {
|
||||
isAccessor = true;
|
||||
this.resetPreviousNodeTrailingComments(key);
|
||||
prop.kind = keyName;
|
||||
if (this.match(tt.star)) {
|
||||
isGenerator = true;
|
||||
|
||||
@ -130,26 +130,27 @@ export default class StatementParser extends ExpressionParser {
|
||||
|
||||
// TODO
|
||||
|
||||
/**
|
||||
* cast a Statement to a Directive. This method mutates input statement.
|
||||
*
|
||||
* @param {N.Statement} stmt
|
||||
* @returns {N.Directive}
|
||||
* @memberof StatementParser
|
||||
*/
|
||||
stmtToDirective(stmt: N.Statement): N.Directive {
|
||||
const expr = stmt.expression;
|
||||
const directive = (stmt: any);
|
||||
directive.type = "Directive";
|
||||
directive.value = directive.expression;
|
||||
delete directive.expression;
|
||||
|
||||
const directiveLiteral = this.startNodeAt(expr.start, expr.loc.start);
|
||||
const directive = this.startNodeAt(stmt.start, stmt.loc.start);
|
||||
|
||||
const raw = this.input.slice(expr.start, expr.end);
|
||||
const directiveLiteral = directive.value;
|
||||
const raw = this.input.slice(directiveLiteral.start, directiveLiteral.end);
|
||||
const val = (directiveLiteral.value = raw.slice(1, -1)); // remove quotes
|
||||
|
||||
this.addExtra(directiveLiteral, "raw", raw);
|
||||
this.addExtra(directiveLiteral, "rawValue", val);
|
||||
|
||||
directive.value = this.finishNodeAt(
|
||||
directiveLiteral,
|
||||
"DirectiveLiteral",
|
||||
expr.end,
|
||||
expr.loc.end,
|
||||
);
|
||||
|
||||
return this.finishNodeAt(directive, "Directive", stmt.end, stmt.loc.end);
|
||||
directiveLiteral.type = "DirectiveLiteral";
|
||||
return directive;
|
||||
}
|
||||
|
||||
parseInterpreterDirective(): N.InterpreterDirective | null {
|
||||
@ -1374,6 +1375,7 @@ export default class StatementParser extends ExpressionParser {
|
||||
classBody.body.push(this.parseClassProperty(prop));
|
||||
return true;
|
||||
}
|
||||
this.resetPreviousNodeTrailingComments(key);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1494,6 +1496,7 @@ export default class StatementParser extends ExpressionParser {
|
||||
!this.isLineTerminator()
|
||||
) {
|
||||
// an async method
|
||||
this.resetPreviousNodeTrailingComments(key);
|
||||
const isGenerator = this.eat(tt.star);
|
||||
|
||||
if (publicMember.optional) {
|
||||
@ -1535,6 +1538,7 @@ export default class StatementParser extends ExpressionParser {
|
||||
) {
|
||||
// `get\n*` is an uninitialized property named 'get' followed by a generator.
|
||||
// a getter or setter
|
||||
this.resetPreviousNodeTrailingComments(key);
|
||||
method.kind = key.name;
|
||||
// The so-called parsed name would have been "get/set": get the real name.
|
||||
const isPrivate = this.match(tt.privateName);
|
||||
|
||||
@ -131,8 +131,8 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
}
|
||||
|
||||
stmtToDirective(stmt: N.Statement): N.Directive {
|
||||
const directive = super.stmtToDirective(stmt);
|
||||
const value = stmt.expression.value;
|
||||
const directive = super.stmtToDirective(stmt);
|
||||
|
||||
// Record the expression value as in estree mode we want
|
||||
// the stmt to have the real value e.g. ("use strict") and
|
||||
|
||||
@ -3212,7 +3212,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
return fileNode;
|
||||
}
|
||||
|
||||
skipBlockComment(): void {
|
||||
skipBlockComment(): N.CommentBlock | void {
|
||||
if (this.hasPlugin("flowComments") && this.skipFlowComment()) {
|
||||
if (this.state.hasFlowComment) {
|
||||
this.unexpected(null, FlowErrors.NestedFlowComment);
|
||||
@ -3232,7 +3232,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
return;
|
||||
}
|
||||
|
||||
super.skipBlockComment();
|
||||
return super.skipBlockComment();
|
||||
}
|
||||
|
||||
skipFlowComment(): number | boolean {
|
||||
|
||||
@ -4,7 +4,6 @@
|
||||
|
||||
import type { Options } from "../options";
|
||||
import * as N from "../types";
|
||||
import type { Position } from "../util/location";
|
||||
import * as charCodes from "charcodes";
|
||||
import { isIdentifierStart, isIdentifierChar } from "../util/identifier";
|
||||
import { types as tt, keywords as keywordTypes, type TokenType } from "./types";
|
||||
@ -304,28 +303,7 @@ export default class Tokenizer extends ParserErrors {
|
||||
}
|
||||
}
|
||||
|
||||
pushComment(
|
||||
block: boolean,
|
||||
text: string,
|
||||
start: number,
|
||||
end: number,
|
||||
startLoc: Position,
|
||||
endLoc: Position,
|
||||
): void {
|
||||
const comment = {
|
||||
type: block ? "CommentBlock" : "CommentLine",
|
||||
value: text,
|
||||
start: start,
|
||||
end: end,
|
||||
loc: new SourceLocation(startLoc, endLoc),
|
||||
};
|
||||
|
||||
if (this.options.tokens) this.pushToken(comment);
|
||||
this.state.comments.push(comment);
|
||||
this.addComment(comment);
|
||||
}
|
||||
|
||||
skipBlockComment(): void {
|
||||
skipBlockComment(): N.CommentBlock | void {
|
||||
let startLoc;
|
||||
if (!this.isLookahead) startLoc = this.state.curPosition();
|
||||
const start = this.state.pos;
|
||||
@ -348,17 +326,19 @@ export default class Tokenizer extends ParserErrors {
|
||||
if (this.isLookahead) return;
|
||||
/*:: invariant(startLoc) */
|
||||
|
||||
this.pushComment(
|
||||
true,
|
||||
this.input.slice(start + 2, end),
|
||||
start,
|
||||
this.state.pos,
|
||||
startLoc,
|
||||
this.state.curPosition(),
|
||||
);
|
||||
const value = this.input.slice(start + 2, end);
|
||||
const comment = {
|
||||
type: "CommentBlock",
|
||||
value: value,
|
||||
start: start,
|
||||
end: end + 2,
|
||||
loc: new SourceLocation(startLoc, this.state.curPosition()),
|
||||
};
|
||||
if (this.options.tokens) this.pushToken(comment);
|
||||
return comment;
|
||||
}
|
||||
|
||||
skipLineComment(startSkip: number): void {
|
||||
skipLineComment(startSkip: number): N.CommentLine | void {
|
||||
const start = this.state.pos;
|
||||
let startLoc;
|
||||
if (!this.isLookahead) startLoc = this.state.curPosition();
|
||||
@ -374,20 +354,26 @@ export default class Tokenizer extends ParserErrors {
|
||||
if (this.isLookahead) return;
|
||||
/*:: invariant(startLoc) */
|
||||
|
||||
this.pushComment(
|
||||
false,
|
||||
this.input.slice(start + startSkip, this.state.pos),
|
||||
const end = this.state.pos;
|
||||
const value = this.input.slice(start + startSkip, end);
|
||||
|
||||
const comment = {
|
||||
type: "CommentLine",
|
||||
value,
|
||||
start,
|
||||
this.state.pos,
|
||||
startLoc,
|
||||
this.state.curPosition(),
|
||||
);
|
||||
end,
|
||||
loc: new SourceLocation(startLoc, this.state.curPosition()),
|
||||
};
|
||||
if (this.options.tokens) this.pushToken(comment);
|
||||
return comment;
|
||||
}
|
||||
|
||||
// Called at the start of the parse and after every token. Skips
|
||||
// whitespace and comments, and.
|
||||
|
||||
skipSpace(): void {
|
||||
const spaceStart = this.state.pos;
|
||||
const comments = [];
|
||||
loop: while (this.state.pos < this.length) {
|
||||
const ch = this.input.charCodeAt(this.state.pos);
|
||||
switch (ch) {
|
||||
@ -413,13 +399,23 @@ export default class Tokenizer extends ParserErrors {
|
||||
|
||||
case charCodes.slash:
|
||||
switch (this.input.charCodeAt(this.state.pos + 1)) {
|
||||
case charCodes.asterisk:
|
||||
this.skipBlockComment();
|
||||
case charCodes.asterisk: {
|
||||
const comment = this.skipBlockComment();
|
||||
if (comment !== undefined) {
|
||||
this.addComment(comment);
|
||||
comments.push(comment);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case charCodes.slash:
|
||||
this.skipLineComment(2);
|
||||
case charCodes.slash: {
|
||||
const comment = this.skipLineComment(2);
|
||||
if (comment !== undefined) {
|
||||
this.addComment(comment);
|
||||
comments.push(comment);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break loop;
|
||||
@ -429,11 +425,56 @@ export default class Tokenizer extends ParserErrors {
|
||||
default:
|
||||
if (isWhitespace(ch)) {
|
||||
++this.state.pos;
|
||||
} else if (ch === charCodes.dash && !this.inModule) {
|
||||
const pos = this.state.pos;
|
||||
if (
|
||||
this.input.charCodeAt(pos + 1) === charCodes.dash &&
|
||||
this.input.charCodeAt(pos + 2) === charCodes.greaterThan &&
|
||||
(spaceStart === 0 || this.state.lineStart > spaceStart)
|
||||
) {
|
||||
// A `-->` line comment
|
||||
const comment = this.skipLineComment(3);
|
||||
if (comment !== undefined) {
|
||||
this.addComment(comment);
|
||||
comments.push(comment);
|
||||
}
|
||||
} else {
|
||||
break loop;
|
||||
}
|
||||
} else if (ch === charCodes.lessThan && !this.inModule) {
|
||||
const pos = this.state.pos;
|
||||
if (
|
||||
this.input.charCodeAt(pos + 1) === charCodes.exclamationMark &&
|
||||
this.input.charCodeAt(pos + 2) === charCodes.dash &&
|
||||
this.input.charCodeAt(pos + 3) === charCodes.dash
|
||||
) {
|
||||
// `<!--`, an XML-style comment that should be interpreted as a line comment
|
||||
const comment = this.skipLineComment(4);
|
||||
if (comment !== undefined) {
|
||||
this.addComment(comment);
|
||||
comments.push(comment);
|
||||
}
|
||||
} else {
|
||||
break loop;
|
||||
}
|
||||
} else {
|
||||
break loop;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (comments.length > 0) {
|
||||
const end = this.state.pos;
|
||||
const CommentWhitespace = {
|
||||
start: spaceStart,
|
||||
end,
|
||||
comments,
|
||||
leadingNode: null,
|
||||
trailingNode: null,
|
||||
containingNode: null,
|
||||
};
|
||||
this.state.commentStack.push(CommentWhitespace);
|
||||
}
|
||||
}
|
||||
|
||||
// Called at the end of every token. Sets `end`, `val`, and
|
||||
@ -661,18 +702,6 @@ export default class Tokenizer extends ParserErrors {
|
||||
const next = this.input.charCodeAt(this.state.pos + 1);
|
||||
|
||||
if (next === code) {
|
||||
if (
|
||||
next === charCodes.dash &&
|
||||
!this.inModule &&
|
||||
this.input.charCodeAt(this.state.pos + 2) === charCodes.greaterThan &&
|
||||
(this.state.lastTokEnd === 0 || this.hasPrecedingLineBreak())
|
||||
) {
|
||||
// A `-->` line comment
|
||||
this.skipLineComment(3);
|
||||
this.skipSpace();
|
||||
this.nextToken();
|
||||
return;
|
||||
}
|
||||
this.finishOp(tt.incDec, 2);
|
||||
return;
|
||||
}
|
||||
@ -703,20 +732,6 @@ export default class Tokenizer extends ParserErrors {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
next === charCodes.exclamationMark &&
|
||||
code === charCodes.lessThan &&
|
||||
!this.inModule &&
|
||||
this.input.charCodeAt(this.state.pos + 2) === charCodes.dash &&
|
||||
this.input.charCodeAt(this.state.pos + 3) === charCodes.dash
|
||||
) {
|
||||
// `<!--`, an XML-style comment that should be interpreted as a line comment
|
||||
this.skipLineComment(4);
|
||||
this.skipSpace();
|
||||
this.nextToken();
|
||||
return;
|
||||
}
|
||||
|
||||
if (next === charCodes.equalsTo) {
|
||||
// <= | >=
|
||||
size = 2;
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
import type { Options } from "../options";
|
||||
import * as N from "../types";
|
||||
import type { CommentWhitespace } from "../parser/comments";
|
||||
import { Position } from "../util/location";
|
||||
|
||||
import { types as ct, type TokContext } from "./context";
|
||||
@ -89,20 +90,11 @@ export default class State {
|
||||
// where @foo belongs to the outer class and @bar to the inner
|
||||
decoratorStack: Array<Array<N.Decorator>> = [[]];
|
||||
|
||||
// Comment store.
|
||||
// Comment store for Program.comments
|
||||
comments: Array<N.Comment> = [];
|
||||
|
||||
// Comment attachment store
|
||||
trailingComments: Array<N.Comment> = [];
|
||||
leadingComments: Array<N.Comment> = [];
|
||||
commentStack: Array<{
|
||||
start: number,
|
||||
leadingComments: ?Array<N.Comment>,
|
||||
trailingComments: ?Array<N.Comment>,
|
||||
type: string,
|
||||
}> = [];
|
||||
// $FlowIgnore this is initialized when the parser starts.
|
||||
commentPreviousNode: N.Node = null;
|
||||
commentStack: Array<CommentWhitespace> = [];
|
||||
|
||||
// The current position of the tokenizer in the input.
|
||||
pos: number = 0;
|
||||
|
||||
@ -16,7 +16,7 @@ import type { ParsingError } from "./parser/error";
|
||||
* - packages/babel-generators/src/generators
|
||||
*/
|
||||
|
||||
export type Comment = {
|
||||
type CommentBase = {
|
||||
type: "CommentBlock" | "CommentLine",
|
||||
value: string,
|
||||
start: number,
|
||||
@ -24,6 +24,26 @@ export type Comment = {
|
||||
loc: SourceLocation,
|
||||
};
|
||||
|
||||
export type CommentBlock = CommentBase & {
|
||||
type: "CommentBlock",
|
||||
};
|
||||
|
||||
export type CommentLine = CommentBase & {
|
||||
type: "CommentLine",
|
||||
};
|
||||
|
||||
export type Comment = CommentBlock | CommentLine;
|
||||
|
||||
// A whitespace containing comments
|
||||
export type CommentWhitespace = {
|
||||
start: number,
|
||||
end: number,
|
||||
comments: Array<Comment>,
|
||||
leadingNode: Node | null,
|
||||
trailingNode: Node | null,
|
||||
containerNode: Node | null,
|
||||
};
|
||||
|
||||
export interface NodeBase {
|
||||
start: number;
|
||||
end: number;
|
||||
|
||||
3
packages/babel-parser/test/fixtures/comments/basic/arrow-function/input.js
vendored
Normal file
3
packages/babel-parser/test/fixtures/comments/basic/arrow-function/input.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
(/*1*/)=>x;
|
||||
|
||||
(/*1*/x/*2*/,/*3*/) /*4*/ => /*5*/ {}
|
||||
126
packages/babel-parser/test/fixtures/comments/basic/arrow-function/output.json
vendored
Normal file
126
packages/babel-parser/test/fixtures/comments/basic/arrow-function/output.json
vendored
Normal file
@ -0,0 +1,126 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":50,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":37}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":50,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":37}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":0,"end":11,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":11}},
|
||||
"expression": {
|
||||
"type": "ArrowFunctionExpression",
|
||||
"start":0,"end":10,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":10}},
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "1",
|
||||
"start":1,"end":6,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":6}}
|
||||
}
|
||||
],
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "Identifier",
|
||||
"start":9,"end":10,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":10},"identifierName":"x"},
|
||||
"name": "x"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":13,"end":50,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":37}},
|
||||
"expression": {
|
||||
"type": "ArrowFunctionExpression",
|
||||
"start":13,"end":50,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":37}},
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "4",
|
||||
"start":33,"end":38,"loc":{"start":{"line":3,"column":20},"end":{"line":3,"column":25}}
|
||||
}
|
||||
],
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [
|
||||
{
|
||||
"type": "Identifier",
|
||||
"start":19,"end":20,"loc":{"start":{"line":3,"column":6},"end":{"line":3,"column":7},"identifierName":"x"},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "1",
|
||||
"start":14,"end":19,"loc":{"start":{"line":3,"column":1},"end":{"line":3,"column":6}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "2",
|
||||
"start":20,"end":25,"loc":{"start":{"line":3,"column":7},"end":{"line":3,"column":12}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "3",
|
||||
"start":26,"end":31,"loc":{"start":{"line":3,"column":13},"end":{"line":3,"column":18}}
|
||||
}
|
||||
],
|
||||
"name": "x"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":48,"end":50,"loc":{"start":{"line":3,"column":35},"end":{"line":3,"column":37}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "5",
|
||||
"start":42,"end":47,"loc":{"start":{"line":3,"column":29},"end":{"line":3,"column":34}}
|
||||
}
|
||||
],
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
},
|
||||
"comments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "1",
|
||||
"start":1,"end":6,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":6}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "1",
|
||||
"start":14,"end":19,"loc":{"start":{"line":3,"column":1},"end":{"line":3,"column":6}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "2",
|
||||
"start":20,"end":25,"loc":{"start":{"line":3,"column":7},"end":{"line":3,"column":12}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "3",
|
||||
"start":26,"end":31,"loc":{"start":{"line":3,"column":13},"end":{"line":3,"column":18}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "4",
|
||||
"start":33,"end":38,"loc":{"start":{"line":3,"column":20},"end":{"line":3,"column":25}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "5",
|
||||
"start":42,"end":47,"loc":{"start":{"line":3,"column":29},"end":{"line":3,"column":34}}
|
||||
}
|
||||
]
|
||||
}
|
||||
3
packages/babel-parser/test/fixtures/comments/basic/async-arrow-function/input.js
vendored
Normal file
3
packages/babel-parser/test/fixtures/comments/basic/async-arrow-function/input.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
/* 1 */ async /* 2 */ (/* 3 */) /* 4 */=>x;
|
||||
|
||||
/* 1 */ async /* 2 */ (/* 3 */x/* 4 */) /* 5 */ => /* 6 */ {}
|
||||
177
packages/babel-parser/test/fixtures/comments/basic/async-arrow-function/output.json
vendored
Normal file
177
packages/babel-parser/test/fixtures/comments/basic/async-arrow-function/output.json
vendored
Normal file
@ -0,0 +1,177 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":106,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":61}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":106,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":61}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":8,"end":43,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":43}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":0,"end":7,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":7}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":45,"end":52,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":7}}
|
||||
}
|
||||
],
|
||||
"expression": {
|
||||
"type": "ArrowFunctionExpression",
|
||||
"start":8,"end":42,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":42}},
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":14,"end":21,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":21}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":23,"end":30,"loc":{"start":{"line":1,"column":23},"end":{"line":1,"column":30}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":32,"end":39,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":39}}
|
||||
}
|
||||
],
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": true,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "Identifier",
|
||||
"start":41,"end":42,"loc":{"start":{"line":1,"column":41},"end":{"line":1,"column":42},"identifierName":"x"},
|
||||
"name": "x"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":53,"end":106,"loc":{"start":{"line":3,"column":8},"end":{"line":3,"column":61}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":45,"end":52,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":7}}
|
||||
}
|
||||
],
|
||||
"expression": {
|
||||
"type": "ArrowFunctionExpression",
|
||||
"start":53,"end":106,"loc":{"start":{"line":3,"column":8},"end":{"line":3,"column":61}},
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":59,"end":66,"loc":{"start":{"line":3,"column":14},"end":{"line":3,"column":21}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":85,"end":92,"loc":{"start":{"line":3,"column":40},"end":{"line":3,"column":47}}
|
||||
}
|
||||
],
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": true,
|
||||
"params": [
|
||||
{
|
||||
"type": "Identifier",
|
||||
"start":75,"end":76,"loc":{"start":{"line":3,"column":30},"end":{"line":3,"column":31},"identifierName":"x"},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":68,"end":75,"loc":{"start":{"line":3,"column":23},"end":{"line":3,"column":30}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":76,"end":83,"loc":{"start":{"line":3,"column":31},"end":{"line":3,"column":38}}
|
||||
}
|
||||
],
|
||||
"name": "x"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":104,"end":106,"loc":{"start":{"line":3,"column":59},"end":{"line":3,"column":61}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 6 ",
|
||||
"start":96,"end":103,"loc":{"start":{"line":3,"column":51},"end":{"line":3,"column":58}}
|
||||
}
|
||||
],
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
},
|
||||
"comments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":0,"end":7,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":7}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":14,"end":21,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":21}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":23,"end":30,"loc":{"start":{"line":1,"column":23},"end":{"line":1,"column":30}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":32,"end":39,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":39}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":45,"end":52,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":7}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":59,"end":66,"loc":{"start":{"line":3,"column":14},"end":{"line":3,"column":21}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":68,"end":75,"loc":{"start":{"line":3,"column":23},"end":{"line":3,"column":30}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":76,"end":83,"loc":{"start":{"line":3,"column":31},"end":{"line":3,"column":38}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":85,"end":92,"loc":{"start":{"line":3,"column":40},"end":{"line":3,"column":47}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 6 ",
|
||||
"start":96,"end":103,"loc":{"start":{"line":3,"column":51},"end":{"line":3,"column":58}}
|
||||
}
|
||||
]
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/comments/basic/async-call-expression/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/comments/basic/async-call-expression/input.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
async /* 1 */ (/* 2 */) /* 3 */
|
||||
65
packages/babel-parser/test/fixtures/comments/basic/async-call-expression/output.json
vendored
Normal file
65
packages/babel-parser/test/fixtures/comments/basic/async-call-expression/output.json
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":31,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":31}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":31,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":31}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":0,"end":23,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":23}},
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":24,"end":31,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":31}}
|
||||
}
|
||||
],
|
||||
"expression": {
|
||||
"type": "CallExpression",
|
||||
"start":0,"end":23,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":23}},
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":15,"end":22,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":22}}
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"type": "Identifier",
|
||||
"start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5},"identifierName":"async"},
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":6,"end":13,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":13}}
|
||||
}
|
||||
],
|
||||
"name": "async"
|
||||
},
|
||||
"arguments": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
},
|
||||
"comments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":6,"end":13,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":13}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":15,"end":22,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":22}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":24,"end":31,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":31}}
|
||||
}
|
||||
]
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/comments/basic/async-do-expression/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/comments/basic/async-do-expression/input.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
/* 1 */async/* 2 */do/* 3 */{/* 4 */}/* 5 */
|
||||
3
packages/babel-parser/test/fixtures/comments/basic/async-do-expression/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/comments/basic/async-do-expression/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["asyncDoExpressions", "doExpressions"]
|
||||
}
|
||||
90
packages/babel-parser/test/fixtures/comments/basic/async-do-expression/output.json
vendored
Normal file
90
packages/babel-parser/test/fixtures/comments/basic/async-do-expression/output.json
vendored
Normal file
@ -0,0 +1,90 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":44,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":44}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":44,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":44}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":7,"end":37,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":37}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":0,"end":7,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":7}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":37,"end":44,"loc":{"start":{"line":1,"column":37},"end":{"line":1,"column":44}}
|
||||
}
|
||||
],
|
||||
"expression": {
|
||||
"type": "DoExpression",
|
||||
"start":7,"end":37,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":37}},
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":12,"end":19,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":19}}
|
||||
}
|
||||
],
|
||||
"async": true,
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":28,"end":37,"loc":{"start":{"line":1,"column":28},"end":{"line":1,"column":37}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":21,"end":28,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":28}}
|
||||
}
|
||||
],
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":29,"end":36,"loc":{"start":{"line":1,"column":29},"end":{"line":1,"column":36}}
|
||||
}
|
||||
],
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
},
|
||||
"comments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":0,"end":7,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":7}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":12,"end":19,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":19}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":21,"end":28,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":28}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":29,"end":36,"loc":{"start":{"line":1,"column":29},"end":{"line":1,"column":36}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":37,"end":44,"loc":{"start":{"line":1,"column":37},"end":{"line":1,"column":44}}
|
||||
}
|
||||
]
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/comments/basic/async-function/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/comments/basic/async-function/input.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
/* 1 */async/* 2 */function f () {}
|
||||
57
packages/babel-parser/test/fixtures/comments/basic/async-function/output.json
vendored
Normal file
57
packages/babel-parser/test/fixtures/comments/basic/async-function/output.json
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":35}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":35}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "FunctionDeclaration",
|
||||
"start":7,"end":35,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":35}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":0,"end":7,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":7}}
|
||||
}
|
||||
],
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":12,"end":19,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":19}}
|
||||
}
|
||||
],
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":28,"end":29,"loc":{"start":{"line":1,"column":28},"end":{"line":1,"column":29},"identifierName":"f"},
|
||||
"name": "f"
|
||||
},
|
||||
"generator": false,
|
||||
"async": true,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":33,"end":35,"loc":{"start":{"line":1,"column":33},"end":{"line":1,"column":35}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
},
|
||||
"comments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":0,"end":7,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":7}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":12,"end":19,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":19}}
|
||||
}
|
||||
]
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/comments/basic/call-expression-no-argument/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/comments/basic/call-expression-no-argument/input.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
foo /* 1 */ (/* 2 */)
|
||||
53
packages/babel-parser/test/fixtures/comments/basic/call-expression-no-argument/output.json
vendored
Normal file
53
packages/babel-parser/test/fixtures/comments/basic/call-expression-no-argument/output.json
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":21,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":21}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":21,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":21}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":0,"end":21,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":21}},
|
||||
"expression": {
|
||||
"type": "CallExpression",
|
||||
"start":0,"end":21,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":21}},
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":13,"end":20,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":20}}
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"type": "Identifier",
|
||||
"start":0,"end":3,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":3},"identifierName":"foo"},
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":4,"end":11,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":11}}
|
||||
}
|
||||
],
|
||||
"name": "foo"
|
||||
},
|
||||
"arguments": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
},
|
||||
"comments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":4,"end":11,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":11}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":13,"end":20,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":20}}
|
||||
}
|
||||
]
|
||||
}
|
||||
3
packages/babel-parser/test/fixtures/comments/basic/class-accessor-computed/input.js
vendored
Normal file
3
packages/babel-parser/test/fixtures/comments/basic/class-accessor-computed/input.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
(class { /* 1 */ set /* 2 */ [ /* 3 */f/* 4 */] /* 5 */ (/* 6 */ a /* 7 */, /* 8 */) /* 9 */ {} });
|
||||
(class { /* 1 */ get /* 2 */ [ /* 3 */f/* 4 */] /* 5 */ (/* 6 */) /* 7 */ {} });
|
||||
(class { get /* 1 */ [f] () {} });
|
||||
343
packages/babel-parser/test/fixtures/comments/basic/class-accessor-computed/output.json
vendored
Normal file
343
packages/babel-parser/test/fixtures/comments/basic/class-accessor-computed/output.json
vendored
Normal file
@ -0,0 +1,343 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":215,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":34}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":215,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":34}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":0,"end":99,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":99}},
|
||||
"expression": {
|
||||
"type": "ClassExpression",
|
||||
"start":1,"end":97,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":97}},
|
||||
"extra": {
|
||||
"parenthesized": true,
|
||||
"parenStart": 0
|
||||
},
|
||||
"id": null,
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":7,"end":97,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":97}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassMethod",
|
||||
"start":17,"end":95,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":95}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":9,"end":16,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":16}}
|
||||
}
|
||||
],
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":21,"end":28,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":28}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":48,"end":55,"loc":{"start":{"line":1,"column":48},"end":{"line":1,"column":55}}
|
||||
}
|
||||
],
|
||||
"static": false,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":38,"end":39,"loc":{"start":{"line":1,"column":38},"end":{"line":1,"column":39},"identifierName":"f"},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":31,"end":38,"loc":{"start":{"line":1,"column":31},"end":{"line":1,"column":38}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":39,"end":46,"loc":{"start":{"line":1,"column":39},"end":{"line":1,"column":46}}
|
||||
}
|
||||
],
|
||||
"name": "f"
|
||||
},
|
||||
"computed": true,
|
||||
"kind": "set",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [
|
||||
{
|
||||
"type": "Identifier",
|
||||
"start":65,"end":66,"loc":{"start":{"line":1,"column":65},"end":{"line":1,"column":66},"identifierName":"a"},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 6 ",
|
||||
"start":57,"end":64,"loc":{"start":{"line":1,"column":57},"end":{"line":1,"column":64}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 7 ",
|
||||
"start":67,"end":74,"loc":{"start":{"line":1,"column":67},"end":{"line":1,"column":74}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 8 ",
|
||||
"start":76,"end":83,"loc":{"start":{"line":1,"column":76},"end":{"line":1,"column":83}}
|
||||
}
|
||||
],
|
||||
"name": "a"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":93,"end":95,"loc":{"start":{"line":1,"column":93},"end":{"line":1,"column":95}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 9 ",
|
||||
"start":85,"end":92,"loc":{"start":{"line":1,"column":85},"end":{"line":1,"column":92}}
|
||||
}
|
||||
],
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":100,"end":180,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":80}},
|
||||
"expression": {
|
||||
"type": "ClassExpression",
|
||||
"start":101,"end":178,"loc":{"start":{"line":2,"column":1},"end":{"line":2,"column":78}},
|
||||
"extra": {
|
||||
"parenthesized": true,
|
||||
"parenStart": 100
|
||||
},
|
||||
"id": null,
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":107,"end":178,"loc":{"start":{"line":2,"column":7},"end":{"line":2,"column":78}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassMethod",
|
||||
"start":117,"end":176,"loc":{"start":{"line":2,"column":17},"end":{"line":2,"column":76}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":109,"end":116,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":16}}
|
||||
}
|
||||
],
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":121,"end":128,"loc":{"start":{"line":2,"column":21},"end":{"line":2,"column":28}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":148,"end":155,"loc":{"start":{"line":2,"column":48},"end":{"line":2,"column":55}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 6 ",
|
||||
"start":157,"end":164,"loc":{"start":{"line":2,"column":57},"end":{"line":2,"column":64}}
|
||||
}
|
||||
],
|
||||
"static": false,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":138,"end":139,"loc":{"start":{"line":2,"column":38},"end":{"line":2,"column":39},"identifierName":"f"},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":131,"end":138,"loc":{"start":{"line":2,"column":31},"end":{"line":2,"column":38}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":139,"end":146,"loc":{"start":{"line":2,"column":39},"end":{"line":2,"column":46}}
|
||||
}
|
||||
],
|
||||
"name": "f"
|
||||
},
|
||||
"computed": true,
|
||||
"kind": "get",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":174,"end":176,"loc":{"start":{"line":2,"column":74},"end":{"line":2,"column":76}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 7 ",
|
||||
"start":166,"end":173,"loc":{"start":{"line":2,"column":66},"end":{"line":2,"column":73}}
|
||||
}
|
||||
],
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":181,"end":215,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":34}},
|
||||
"expression": {
|
||||
"type": "ClassExpression",
|
||||
"start":182,"end":213,"loc":{"start":{"line":3,"column":1},"end":{"line":3,"column":32}},
|
||||
"extra": {
|
||||
"parenthesized": true,
|
||||
"parenStart": 181
|
||||
},
|
||||
"id": null,
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":188,"end":213,"loc":{"start":{"line":3,"column":7},"end":{"line":3,"column":32}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassMethod",
|
||||
"start":190,"end":211,"loc":{"start":{"line":3,"column":9},"end":{"line":3,"column":30}},
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":194,"end":201,"loc":{"start":{"line":3,"column":13},"end":{"line":3,"column":20}}
|
||||
}
|
||||
],
|
||||
"static": false,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":203,"end":204,"loc":{"start":{"line":3,"column":22},"end":{"line":3,"column":23},"identifierName":"f"},
|
||||
"name": "f"
|
||||
},
|
||||
"computed": true,
|
||||
"kind": "get",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":209,"end":211,"loc":{"start":{"line":3,"column":28},"end":{"line":3,"column":30}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
},
|
||||
"comments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":9,"end":16,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":16}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":21,"end":28,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":28}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":31,"end":38,"loc":{"start":{"line":1,"column":31},"end":{"line":1,"column":38}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":39,"end":46,"loc":{"start":{"line":1,"column":39},"end":{"line":1,"column":46}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":48,"end":55,"loc":{"start":{"line":1,"column":48},"end":{"line":1,"column":55}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 6 ",
|
||||
"start":57,"end":64,"loc":{"start":{"line":1,"column":57},"end":{"line":1,"column":64}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 7 ",
|
||||
"start":67,"end":74,"loc":{"start":{"line":1,"column":67},"end":{"line":1,"column":74}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 8 ",
|
||||
"start":76,"end":83,"loc":{"start":{"line":1,"column":76},"end":{"line":1,"column":83}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 9 ",
|
||||
"start":85,"end":92,"loc":{"start":{"line":1,"column":85},"end":{"line":1,"column":92}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":109,"end":116,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":16}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":121,"end":128,"loc":{"start":{"line":2,"column":21},"end":{"line":2,"column":28}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":131,"end":138,"loc":{"start":{"line":2,"column":31},"end":{"line":2,"column":38}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":139,"end":146,"loc":{"start":{"line":2,"column":39},"end":{"line":2,"column":46}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":148,"end":155,"loc":{"start":{"line":2,"column":48},"end":{"line":2,"column":55}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 6 ",
|
||||
"start":157,"end":164,"loc":{"start":{"line":2,"column":57},"end":{"line":2,"column":64}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 7 ",
|
||||
"start":166,"end":173,"loc":{"start":{"line":2,"column":66},"end":{"line":2,"column":73}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":194,"end":201,"loc":{"start":{"line":3,"column":13},"end":{"line":3,"column":20}}
|
||||
}
|
||||
]
|
||||
}
|
||||
2
packages/babel-parser/test/fixtures/comments/basic/class-method-async-generator/input.js
vendored
Normal file
2
packages/babel-parser/test/fixtures/comments/basic/class-method-async-generator/input.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
class C { /* 1 */ async /* 2 */ * /* 3 */ f /* 4 */ (/* 5 */ a /* 6 */, /* 7 */) /* 8 */ {} }
|
||||
(class { async /* 1 */ *f () {} });
|
||||
207
packages/babel-parser/test/fixtures/comments/basic/class-method-async-generator/output.json
vendored
Normal file
207
packages/babel-parser/test/fixtures/comments/basic/class-method-async-generator/output.json
vendored
Normal file
@ -0,0 +1,207 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":129,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":35}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":129,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":35}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassDeclaration",
|
||||
"start":0,"end":93,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":93}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"C"},
|
||||
"name": "C"
|
||||
},
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":8,"end":93,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":93}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassMethod",
|
||||
"start":18,"end":91,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":91}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":10,"end":17,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":17}}
|
||||
}
|
||||
],
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":24,"end":31,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":31}}
|
||||
}
|
||||
],
|
||||
"static": false,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":42,"end":43,"loc":{"start":{"line":1,"column":42},"end":{"line":1,"column":43},"identifierName":"f"},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":34,"end":41,"loc":{"start":{"line":1,"column":34},"end":{"line":1,"column":41}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":44,"end":51,"loc":{"start":{"line":1,"column":44},"end":{"line":1,"column":51}}
|
||||
}
|
||||
],
|
||||
"name": "f"
|
||||
},
|
||||
"computed": false,
|
||||
"kind": "method",
|
||||
"id": null,
|
||||
"generator": true,
|
||||
"async": true,
|
||||
"params": [
|
||||
{
|
||||
"type": "Identifier",
|
||||
"start":61,"end":62,"loc":{"start":{"line":1,"column":61},"end":{"line":1,"column":62},"identifierName":"a"},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":53,"end":60,"loc":{"start":{"line":1,"column":53},"end":{"line":1,"column":60}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 6 ",
|
||||
"start":63,"end":70,"loc":{"start":{"line":1,"column":63},"end":{"line":1,"column":70}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 7 ",
|
||||
"start":72,"end":79,"loc":{"start":{"line":1,"column":72},"end":{"line":1,"column":79}}
|
||||
}
|
||||
],
|
||||
"name": "a"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":89,"end":91,"loc":{"start":{"line":1,"column":89},"end":{"line":1,"column":91}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 8 ",
|
||||
"start":81,"end":88,"loc":{"start":{"line":1,"column":81},"end":{"line":1,"column":88}}
|
||||
}
|
||||
],
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":94,"end":129,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":35}},
|
||||
"expression": {
|
||||
"type": "ClassExpression",
|
||||
"start":95,"end":127,"loc":{"start":{"line":2,"column":1},"end":{"line":2,"column":33}},
|
||||
"extra": {
|
||||
"parenthesized": true,
|
||||
"parenStart": 94
|
||||
},
|
||||
"id": null,
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":101,"end":127,"loc":{"start":{"line":2,"column":7},"end":{"line":2,"column":33}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassMethod",
|
||||
"start":103,"end":125,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":31}},
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":109,"end":116,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":22}}
|
||||
}
|
||||
],
|
||||
"static": false,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":118,"end":119,"loc":{"start":{"line":2,"column":24},"end":{"line":2,"column":25},"identifierName":"f"},
|
||||
"name": "f"
|
||||
},
|
||||
"computed": false,
|
||||
"kind": "method",
|
||||
"id": null,
|
||||
"generator": true,
|
||||
"async": true,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":123,"end":125,"loc":{"start":{"line":2,"column":29},"end":{"line":2,"column":31}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
},
|
||||
"comments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":10,"end":17,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":17}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":24,"end":31,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":31}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":34,"end":41,"loc":{"start":{"line":1,"column":34},"end":{"line":1,"column":41}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":44,"end":51,"loc":{"start":{"line":1,"column":44},"end":{"line":1,"column":51}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":53,"end":60,"loc":{"start":{"line":1,"column":53},"end":{"line":1,"column":60}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 6 ",
|
||||
"start":63,"end":70,"loc":{"start":{"line":1,"column":63},"end":{"line":1,"column":70}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 7 ",
|
||||
"start":72,"end":79,"loc":{"start":{"line":1,"column":72},"end":{"line":1,"column":79}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 8 ",
|
||||
"start":81,"end":88,"loc":{"start":{"line":1,"column":81},"end":{"line":1,"column":88}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":109,"end":116,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":22}}
|
||||
}
|
||||
]
|
||||
}
|
||||
2
packages/babel-parser/test/fixtures/comments/basic/class-method-static-generator/input.js
vendored
Normal file
2
packages/babel-parser/test/fixtures/comments/basic/class-method-static-generator/input.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
(class /* 1 */ { /* 2 */ static /* 3 */ * /* 4 */ f /* 5 */ (/* 6 */) /* 7 */ { /* 8 */ } /* 9 */ } /* 10 */);
|
||||
|
||||
175
packages/babel-parser/test/fixtures/comments/basic/class-method-static-generator/output.json
vendored
Normal file
175
packages/babel-parser/test/fixtures/comments/basic/class-method-static-generator/output.json
vendored
Normal file
@ -0,0 +1,175 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":110,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":110}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":110,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":110}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":0,"end":110,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":110}},
|
||||
"expression": {
|
||||
"type": "ClassExpression",
|
||||
"start":1,"end":99,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":99}},
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 10 ",
|
||||
"start":100,"end":108,"loc":{"start":{"line":1,"column":100},"end":{"line":1,"column":108}}
|
||||
}
|
||||
],
|
||||
"extra": {
|
||||
"parenthesized": true,
|
||||
"parenStart": 0
|
||||
},
|
||||
"id": null,
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":15,"end":99,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":99}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":7,"end":14,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":14}}
|
||||
}
|
||||
],
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassMethod",
|
||||
"start":25,"end":89,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":89}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":17,"end":24,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":24}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 9 ",
|
||||
"start":90,"end":97,"loc":{"start":{"line":1,"column":90},"end":{"line":1,"column":97}}
|
||||
}
|
||||
],
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":32,"end":39,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":39}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 6 ",
|
||||
"start":61,"end":68,"loc":{"start":{"line":1,"column":61},"end":{"line":1,"column":68}}
|
||||
}
|
||||
],
|
||||
"static": true,
|
||||
"kind": "method",
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":50,"end":51,"loc":{"start":{"line":1,"column":50},"end":{"line":1,"column":51},"identifierName":"f"},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":42,"end":49,"loc":{"start":{"line":1,"column":42},"end":{"line":1,"column":49}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":52,"end":59,"loc":{"start":{"line":1,"column":52},"end":{"line":1,"column":59}}
|
||||
}
|
||||
],
|
||||
"name": "f"
|
||||
},
|
||||
"computed": false,
|
||||
"id": null,
|
||||
"generator": true,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":78,"end":89,"loc":{"start":{"line":1,"column":78},"end":{"line":1,"column":89}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 7 ",
|
||||
"start":70,"end":77,"loc":{"start":{"line":1,"column":70},"end":{"line":1,"column":77}}
|
||||
}
|
||||
],
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 8 ",
|
||||
"start":80,"end":87,"loc":{"start":{"line":1,"column":80},"end":{"line":1,"column":87}}
|
||||
}
|
||||
],
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
},
|
||||
"comments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":7,"end":14,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":14}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":17,"end":24,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":24}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":32,"end":39,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":39}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":42,"end":49,"loc":{"start":{"line":1,"column":42},"end":{"line":1,"column":49}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":52,"end":59,"loc":{"start":{"line":1,"column":52},"end":{"line":1,"column":59}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 6 ",
|
||||
"start":61,"end":68,"loc":{"start":{"line":1,"column":61},"end":{"line":1,"column":68}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 7 ",
|
||||
"start":70,"end":77,"loc":{"start":{"line":1,"column":70},"end":{"line":1,"column":77}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 8 ",
|
||||
"start":80,"end":87,"loc":{"start":{"line":1,"column":80},"end":{"line":1,"column":87}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 9 ",
|
||||
"start":90,"end":97,"loc":{"start":{"line":1,"column":90},"end":{"line":1,"column":97}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 10 ",
|
||||
"start":100,"end":108,"loc":{"start":{"line":1,"column":100},"end":{"line":1,"column":108}}
|
||||
}
|
||||
]
|
||||
}
|
||||
2
packages/babel-parser/test/fixtures/comments/basic/class-method/input.js
vendored
Normal file
2
packages/babel-parser/test/fixtures/comments/basic/class-method/input.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
(/* 1 */ class /* 2 */ { /* 3 */ f /* 4 */ (/* 5 */ a /* 6 */, /* 7 */) /* 8 */ { /* 9 */ } /* 10 */ } /* 11 */);
|
||||
(class /* 1 */ { /* 2 */ #f /* 3 */ (/* 4 */ a /* 5 */, /* 6 */) /* 7 */ { /* 8 */ } /* 9 */ } /* 10 */);
|
||||
362
packages/babel-parser/test/fixtures/comments/basic/class-method/output.json
vendored
Normal file
362
packages/babel-parser/test/fixtures/comments/basic/class-method/output.json
vendored
Normal file
@ -0,0 +1,362 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":219,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":105}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":219,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":105}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":0,"end":113,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":113}},
|
||||
"expression": {
|
||||
"type": "ClassExpression",
|
||||
"start":9,"end":102,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":102}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":1,"end":8,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":8}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 11 ",
|
||||
"start":103,"end":111,"loc":{"start":{"line":1,"column":103},"end":{"line":1,"column":111}}
|
||||
}
|
||||
],
|
||||
"extra": {
|
||||
"parenthesized": true,
|
||||
"parenStart": 0
|
||||
},
|
||||
"id": null,
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":23,"end":102,"loc":{"start":{"line":1,"column":23},"end":{"line":1,"column":102}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":15,"end":22,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":22}}
|
||||
}
|
||||
],
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassMethod",
|
||||
"start":33,"end":91,"loc":{"start":{"line":1,"column":33},"end":{"line":1,"column":91}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":25,"end":32,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":32}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 10 ",
|
||||
"start":92,"end":100,"loc":{"start":{"line":1,"column":92},"end":{"line":1,"column":100}}
|
||||
}
|
||||
],
|
||||
"static": false,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":33,"end":34,"loc":{"start":{"line":1,"column":33},"end":{"line":1,"column":34},"identifierName":"f"},
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":35,"end":42,"loc":{"start":{"line":1,"column":35},"end":{"line":1,"column":42}}
|
||||
}
|
||||
],
|
||||
"name": "f"
|
||||
},
|
||||
"computed": false,
|
||||
"kind": "method",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [
|
||||
{
|
||||
"type": "Identifier",
|
||||
"start":52,"end":53,"loc":{"start":{"line":1,"column":52},"end":{"line":1,"column":53},"identifierName":"a"},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":44,"end":51,"loc":{"start":{"line":1,"column":44},"end":{"line":1,"column":51}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 6 ",
|
||||
"start":54,"end":61,"loc":{"start":{"line":1,"column":54},"end":{"line":1,"column":61}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 7 ",
|
||||
"start":63,"end":70,"loc":{"start":{"line":1,"column":63},"end":{"line":1,"column":70}}
|
||||
}
|
||||
],
|
||||
"name": "a"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":80,"end":91,"loc":{"start":{"line":1,"column":80},"end":{"line":1,"column":91}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 8 ",
|
||||
"start":72,"end":79,"loc":{"start":{"line":1,"column":72},"end":{"line":1,"column":79}}
|
||||
}
|
||||
],
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 9 ",
|
||||
"start":82,"end":89,"loc":{"start":{"line":1,"column":82},"end":{"line":1,"column":89}}
|
||||
}
|
||||
],
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":114,"end":219,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":105}},
|
||||
"expression": {
|
||||
"type": "ClassExpression",
|
||||
"start":115,"end":208,"loc":{"start":{"line":2,"column":1},"end":{"line":2,"column":94}},
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 10 ",
|
||||
"start":209,"end":217,"loc":{"start":{"line":2,"column":95},"end":{"line":2,"column":103}}
|
||||
}
|
||||
],
|
||||
"extra": {
|
||||
"parenthesized": true,
|
||||
"parenStart": 114
|
||||
},
|
||||
"id": null,
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":129,"end":208,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":94}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":121,"end":128,"loc":{"start":{"line":2,"column":7},"end":{"line":2,"column":14}}
|
||||
}
|
||||
],
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassPrivateMethod",
|
||||
"start":139,"end":198,"loc":{"start":{"line":2,"column":25},"end":{"line":2,"column":84}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":131,"end":138,"loc":{"start":{"line":2,"column":17},"end":{"line":2,"column":24}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 9 ",
|
||||
"start":199,"end":206,"loc":{"start":{"line":2,"column":85},"end":{"line":2,"column":92}}
|
||||
}
|
||||
],
|
||||
"static": false,
|
||||
"key": {
|
||||
"type": "PrivateName",
|
||||
"start":139,"end":141,"loc":{"start":{"line":2,"column":25},"end":{"line":2,"column":27}},
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":142,"end":149,"loc":{"start":{"line":2,"column":28},"end":{"line":2,"column":35}}
|
||||
}
|
||||
],
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":140,"end":141,"loc":{"start":{"line":2,"column":26},"end":{"line":2,"column":27},"identifierName":"f"},
|
||||
"name": "f"
|
||||
}
|
||||
},
|
||||
"kind": "method",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [
|
||||
{
|
||||
"type": "Identifier",
|
||||
"start":159,"end":160,"loc":{"start":{"line":2,"column":45},"end":{"line":2,"column":46},"identifierName":"a"},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":151,"end":158,"loc":{"start":{"line":2,"column":37},"end":{"line":2,"column":44}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":161,"end":168,"loc":{"start":{"line":2,"column":47},"end":{"line":2,"column":54}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 6 ",
|
||||
"start":170,"end":177,"loc":{"start":{"line":2,"column":56},"end":{"line":2,"column":63}}
|
||||
}
|
||||
],
|
||||
"name": "a"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":187,"end":198,"loc":{"start":{"line":2,"column":73},"end":{"line":2,"column":84}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 7 ",
|
||||
"start":179,"end":186,"loc":{"start":{"line":2,"column":65},"end":{"line":2,"column":72}}
|
||||
}
|
||||
],
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 8 ",
|
||||
"start":189,"end":196,"loc":{"start":{"line":2,"column":75},"end":{"line":2,"column":82}}
|
||||
}
|
||||
],
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
},
|
||||
"comments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":1,"end":8,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":8}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":15,"end":22,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":22}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":25,"end":32,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":32}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":35,"end":42,"loc":{"start":{"line":1,"column":35},"end":{"line":1,"column":42}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":44,"end":51,"loc":{"start":{"line":1,"column":44},"end":{"line":1,"column":51}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 6 ",
|
||||
"start":54,"end":61,"loc":{"start":{"line":1,"column":54},"end":{"line":1,"column":61}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 7 ",
|
||||
"start":63,"end":70,"loc":{"start":{"line":1,"column":63},"end":{"line":1,"column":70}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 8 ",
|
||||
"start":72,"end":79,"loc":{"start":{"line":1,"column":72},"end":{"line":1,"column":79}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 9 ",
|
||||
"start":82,"end":89,"loc":{"start":{"line":1,"column":82},"end":{"line":1,"column":89}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 10 ",
|
||||
"start":92,"end":100,"loc":{"start":{"line":1,"column":92},"end":{"line":1,"column":100}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 11 ",
|
||||
"start":103,"end":111,"loc":{"start":{"line":1,"column":103},"end":{"line":1,"column":111}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":121,"end":128,"loc":{"start":{"line":2,"column":7},"end":{"line":2,"column":14}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":131,"end":138,"loc":{"start":{"line":2,"column":17},"end":{"line":2,"column":24}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":142,"end":149,"loc":{"start":{"line":2,"column":28},"end":{"line":2,"column":35}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":151,"end":158,"loc":{"start":{"line":2,"column":37},"end":{"line":2,"column":44}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":161,"end":168,"loc":{"start":{"line":2,"column":47},"end":{"line":2,"column":54}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 6 ",
|
||||
"start":170,"end":177,"loc":{"start":{"line":2,"column":56},"end":{"line":2,"column":63}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 7 ",
|
||||
"start":179,"end":186,"loc":{"start":{"line":2,"column":65},"end":{"line":2,"column":72}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 8 ",
|
||||
"start":189,"end":196,"loc":{"start":{"line":2,"column":75},"end":{"line":2,"column":82}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 9 ",
|
||||
"start":199,"end":206,"loc":{"start":{"line":2,"column":85},"end":{"line":2,"column":92}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 10 ",
|
||||
"start":209,"end":217,"loc":{"start":{"line":2,"column":95},"end":{"line":2,"column":103}}
|
||||
}
|
||||
]
|
||||
}
|
||||
2
packages/babel-parser/test/fixtures/comments/basic/class-private-method/input.js
vendored
Normal file
2
packages/babel-parser/test/fixtures/comments/basic/class-private-method/input.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
(/* 1 */ class /* 2 */ { /* 3 */ #f /* 4 */ (/* 5 */ a /* 6 */, /* 7 */) /* 8 */ { /* 9 */ } /* 10 */ } /* 11 */);
|
||||
|
||||
196
packages/babel-parser/test/fixtures/comments/basic/class-private-method/output.json
vendored
Normal file
196
packages/babel-parser/test/fixtures/comments/basic/class-private-method/output.json
vendored
Normal file
@ -0,0 +1,196 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":114,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":114}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":114,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":114}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":0,"end":114,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":114}},
|
||||
"expression": {
|
||||
"type": "ClassExpression",
|
||||
"start":9,"end":103,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":103}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":1,"end":8,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":8}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 11 ",
|
||||
"start":104,"end":112,"loc":{"start":{"line":1,"column":104},"end":{"line":1,"column":112}}
|
||||
}
|
||||
],
|
||||
"extra": {
|
||||
"parenthesized": true,
|
||||
"parenStart": 0
|
||||
},
|
||||
"id": null,
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":23,"end":103,"loc":{"start":{"line":1,"column":23},"end":{"line":1,"column":103}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":15,"end":22,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":22}}
|
||||
}
|
||||
],
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassPrivateMethod",
|
||||
"start":33,"end":92,"loc":{"start":{"line":1,"column":33},"end":{"line":1,"column":92}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":25,"end":32,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":32}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 10 ",
|
||||
"start":93,"end":101,"loc":{"start":{"line":1,"column":93},"end":{"line":1,"column":101}}
|
||||
}
|
||||
],
|
||||
"static": false,
|
||||
"key": {
|
||||
"type": "PrivateName",
|
||||
"start":33,"end":35,"loc":{"start":{"line":1,"column":33},"end":{"line":1,"column":35}},
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":36,"end":43,"loc":{"start":{"line":1,"column":36},"end":{"line":1,"column":43}}
|
||||
}
|
||||
],
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":34,"end":35,"loc":{"start":{"line":1,"column":34},"end":{"line":1,"column":35},"identifierName":"f"},
|
||||
"name": "f"
|
||||
}
|
||||
},
|
||||
"kind": "method",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [
|
||||
{
|
||||
"type": "Identifier",
|
||||
"start":53,"end":54,"loc":{"start":{"line":1,"column":53},"end":{"line":1,"column":54},"identifierName":"a"},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":45,"end":52,"loc":{"start":{"line":1,"column":45},"end":{"line":1,"column":52}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 6 ",
|
||||
"start":55,"end":62,"loc":{"start":{"line":1,"column":55},"end":{"line":1,"column":62}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 7 ",
|
||||
"start":64,"end":71,"loc":{"start":{"line":1,"column":64},"end":{"line":1,"column":71}}
|
||||
}
|
||||
],
|
||||
"name": "a"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":81,"end":92,"loc":{"start":{"line":1,"column":81},"end":{"line":1,"column":92}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 8 ",
|
||||
"start":73,"end":80,"loc":{"start":{"line":1,"column":73},"end":{"line":1,"column":80}}
|
||||
}
|
||||
],
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 9 ",
|
||||
"start":83,"end":90,"loc":{"start":{"line":1,"column":83},"end":{"line":1,"column":90}}
|
||||
}
|
||||
],
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
},
|
||||
"comments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":1,"end":8,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":8}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":15,"end":22,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":22}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":25,"end":32,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":32}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":36,"end":43,"loc":{"start":{"line":1,"column":36},"end":{"line":1,"column":43}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":45,"end":52,"loc":{"start":{"line":1,"column":45},"end":{"line":1,"column":52}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 6 ",
|
||||
"start":55,"end":62,"loc":{"start":{"line":1,"column":55},"end":{"line":1,"column":62}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 7 ",
|
||||
"start":64,"end":71,"loc":{"start":{"line":1,"column":64},"end":{"line":1,"column":71}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 8 ",
|
||||
"start":73,"end":80,"loc":{"start":{"line":1,"column":73},"end":{"line":1,"column":80}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 9 ",
|
||||
"start":83,"end":90,"loc":{"start":{"line":1,"column":83},"end":{"line":1,"column":90}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 10 ",
|
||||
"start":93,"end":101,"loc":{"start":{"line":1,"column":93},"end":{"line":1,"column":101}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 11 ",
|
||||
"start":104,"end":112,"loc":{"start":{"line":1,"column":104},"end":{"line":1,"column":112}}
|
||||
}
|
||||
]
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/comments/basic/class-static-block/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/comments/basic/class-static-block/input.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
(class /* 1 */ { /* 2 */ static /* 3 */ {/* 4 */} /* 5 */ } /* 6 */);
|
||||
3
packages/babel-parser/test/fixtures/comments/basic/class-static-block/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/comments/basic/class-static-block/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["classStaticBlock"]
|
||||
}
|
||||
110
packages/babel-parser/test/fixtures/comments/basic/class-static-block/output.json
vendored
Normal file
110
packages/babel-parser/test/fixtures/comments/basic/class-static-block/output.json
vendored
Normal file
@ -0,0 +1,110 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":69,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":69}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":69,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":69}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":0,"end":69,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":69}},
|
||||
"expression": {
|
||||
"type": "ClassExpression",
|
||||
"start":1,"end":59,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":59}},
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 6 ",
|
||||
"start":60,"end":67,"loc":{"start":{"line":1,"column":60},"end":{"line":1,"column":67}}
|
||||
}
|
||||
],
|
||||
"extra": {
|
||||
"parenthesized": true,
|
||||
"parenStart": 0
|
||||
},
|
||||
"id": null,
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":15,"end":59,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":59}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":7,"end":14,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":14}}
|
||||
}
|
||||
],
|
||||
"body": [
|
||||
{
|
||||
"type": "StaticBlock",
|
||||
"start":25,"end":49,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":49}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":17,"end":24,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":24}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":50,"end":57,"loc":{"start":{"line":1,"column":50},"end":{"line":1,"column":57}}
|
||||
}
|
||||
],
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":32,"end":39,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":39}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":41,"end":48,"loc":{"start":{"line":1,"column":41},"end":{"line":1,"column":48}}
|
||||
}
|
||||
],
|
||||
"body": []
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
},
|
||||
"comments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":7,"end":14,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":14}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":17,"end":24,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":24}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":32,"end":39,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":39}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":41,"end":48,"loc":{"start":{"line":1,"column":41},"end":{"line":1,"column":48}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":50,"end":57,"loc":{"start":{"line":1,"column":50},"end":{"line":1,"column":57}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 6 ",
|
||||
"start":60,"end":67,"loc":{"start":{"line":1,"column":60},"end":{"line":1,"column":67}}
|
||||
}
|
||||
]
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/comments/basic/directive/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/comments/basic/directive/input.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
/* 1 */"use strict"/* 2 */;/* 3 */
|
||||
64
packages/babel-parser/test/fixtures/comments/basic/directive/output.json
vendored
Normal file
64
packages/babel-parser/test/fixtures/comments/basic/directive/output.json
vendored
Normal file
@ -0,0 +1,64 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":34,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":34}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":34,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":34}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [],
|
||||
"directives": [
|
||||
{
|
||||
"type": "Directive",
|
||||
"start":7,"end":27,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":27}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":0,"end":7,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":7}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":27,"end":34,"loc":{"start":{"line":1,"column":27},"end":{"line":1,"column":34}}
|
||||
}
|
||||
],
|
||||
"value": {
|
||||
"type": "DirectiveLiteral",
|
||||
"start":7,"end":19,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":19}},
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":19,"end":26,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":26}}
|
||||
}
|
||||
],
|
||||
"extra": {
|
||||
"rawValue": "use strict",
|
||||
"raw": "\"use strict\""
|
||||
},
|
||||
"value": "use strict"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"comments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":0,"end":7,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":7}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":19,"end":26,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":26}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":27,"end":34,"loc":{"start":{"line":1,"column":27},"end":{"line":1,"column":34}}
|
||||
}
|
||||
]
|
||||
}
|
||||
4
packages/babel-parser/test/fixtures/comments/basic/function/input.js
vendored
Normal file
4
packages/babel-parser/test/fixtures/comments/basic/function/input.js
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
/* 1 */ function /* 2 */ f /* 3 */ (/* 4 */ a /* 5 */, /* 6 */) /* 7 */ { /* 8 */ } /* 9 */
|
||||
(/* 1 */ function /* 2 */ f /* 3 */ (/* 4 */ a /* 5 */, /* 6 */) /* 7 */ { /* 8 */ } /* 9 */);
|
||||
|
||||
|
||||
290
packages/babel-parser/test/fixtures/comments/basic/function/output.json
vendored
Normal file
290
packages/babel-parser/test/fixtures/comments/basic/function/output.json
vendored
Normal file
@ -0,0 +1,290 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":186,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":94}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":186,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":94}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "FunctionDeclaration",
|
||||
"start":8,"end":83,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":83}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":0,"end":7,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":7}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 9 ",
|
||||
"start":84,"end":91,"loc":{"start":{"line":1,"column":84},"end":{"line":1,"column":91}}
|
||||
}
|
||||
],
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":25,"end":26,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":26},"identifierName":"f"},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":17,"end":24,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":24}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":27,"end":34,"loc":{"start":{"line":1,"column":27},"end":{"line":1,"column":34}}
|
||||
}
|
||||
],
|
||||
"name": "f"
|
||||
},
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [
|
||||
{
|
||||
"type": "Identifier",
|
||||
"start":44,"end":45,"loc":{"start":{"line":1,"column":44},"end":{"line":1,"column":45},"identifierName":"a"},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":36,"end":43,"loc":{"start":{"line":1,"column":36},"end":{"line":1,"column":43}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":46,"end":53,"loc":{"start":{"line":1,"column":46},"end":{"line":1,"column":53}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 6 ",
|
||||
"start":55,"end":62,"loc":{"start":{"line":1,"column":55},"end":{"line":1,"column":62}}
|
||||
}
|
||||
],
|
||||
"name": "a"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":72,"end":83,"loc":{"start":{"line":1,"column":72},"end":{"line":1,"column":83}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 7 ",
|
||||
"start":64,"end":71,"loc":{"start":{"line":1,"column":64},"end":{"line":1,"column":71}}
|
||||
}
|
||||
],
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 8 ",
|
||||
"start":74,"end":81,"loc":{"start":{"line":1,"column":74},"end":{"line":1,"column":81}}
|
||||
}
|
||||
],
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":92,"end":186,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":94}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 9 ",
|
||||
"start":84,"end":91,"loc":{"start":{"line":1,"column":84},"end":{"line":1,"column":91}}
|
||||
}
|
||||
],
|
||||
"expression": {
|
||||
"type": "FunctionExpression",
|
||||
"start":101,"end":176,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":84}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":93,"end":100,"loc":{"start":{"line":2,"column":1},"end":{"line":2,"column":8}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 9 ",
|
||||
"start":177,"end":184,"loc":{"start":{"line":2,"column":85},"end":{"line":2,"column":92}}
|
||||
}
|
||||
],
|
||||
"extra": {
|
||||
"parenthesized": true,
|
||||
"parenStart": 92
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":118,"end":119,"loc":{"start":{"line":2,"column":26},"end":{"line":2,"column":27},"identifierName":"f"},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":110,"end":117,"loc":{"start":{"line":2,"column":18},"end":{"line":2,"column":25}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":120,"end":127,"loc":{"start":{"line":2,"column":28},"end":{"line":2,"column":35}}
|
||||
}
|
||||
],
|
||||
"name": "f"
|
||||
},
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [
|
||||
{
|
||||
"type": "Identifier",
|
||||
"start":137,"end":138,"loc":{"start":{"line":2,"column":45},"end":{"line":2,"column":46},"identifierName":"a"},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":129,"end":136,"loc":{"start":{"line":2,"column":37},"end":{"line":2,"column":44}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":139,"end":146,"loc":{"start":{"line":2,"column":47},"end":{"line":2,"column":54}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 6 ",
|
||||
"start":148,"end":155,"loc":{"start":{"line":2,"column":56},"end":{"line":2,"column":63}}
|
||||
}
|
||||
],
|
||||
"name": "a"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":165,"end":176,"loc":{"start":{"line":2,"column":73},"end":{"line":2,"column":84}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 7 ",
|
||||
"start":157,"end":164,"loc":{"start":{"line":2,"column":65},"end":{"line":2,"column":72}}
|
||||
}
|
||||
],
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 8 ",
|
||||
"start":167,"end":174,"loc":{"start":{"line":2,"column":75},"end":{"line":2,"column":82}}
|
||||
}
|
||||
],
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
},
|
||||
"comments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":0,"end":7,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":7}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":17,"end":24,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":24}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":27,"end":34,"loc":{"start":{"line":1,"column":27},"end":{"line":1,"column":34}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":36,"end":43,"loc":{"start":{"line":1,"column":36},"end":{"line":1,"column":43}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":46,"end":53,"loc":{"start":{"line":1,"column":46},"end":{"line":1,"column":53}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 6 ",
|
||||
"start":55,"end":62,"loc":{"start":{"line":1,"column":55},"end":{"line":1,"column":62}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 7 ",
|
||||
"start":64,"end":71,"loc":{"start":{"line":1,"column":64},"end":{"line":1,"column":71}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 8 ",
|
||||
"start":74,"end":81,"loc":{"start":{"line":1,"column":74},"end":{"line":1,"column":81}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 9 ",
|
||||
"start":84,"end":91,"loc":{"start":{"line":1,"column":84},"end":{"line":1,"column":91}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":93,"end":100,"loc":{"start":{"line":2,"column":1},"end":{"line":2,"column":8}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":110,"end":117,"loc":{"start":{"line":2,"column":18},"end":{"line":2,"column":25}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":120,"end":127,"loc":{"start":{"line":2,"column":28},"end":{"line":2,"column":35}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":129,"end":136,"loc":{"start":{"line":2,"column":37},"end":{"line":2,"column":44}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":139,"end":146,"loc":{"start":{"line":2,"column":47},"end":{"line":2,"column":54}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 6 ",
|
||||
"start":148,"end":155,"loc":{"start":{"line":2,"column":56},"end":{"line":2,"column":63}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 7 ",
|
||||
"start":157,"end":164,"loc":{"start":{"line":2,"column":65},"end":{"line":2,"column":72}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 8 ",
|
||||
"start":167,"end":174,"loc":{"start":{"line":2,"column":75},"end":{"line":2,"column":82}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 9 ",
|
||||
"start":177,"end":184,"loc":{"start":{"line":2,"column":85},"end":{"line":2,"column":92}}
|
||||
}
|
||||
]
|
||||
}
|
||||
3
packages/babel-parser/test/fixtures/comments/basic/object-accessor-computed/input.js
vendored
Normal file
3
packages/babel-parser/test/fixtures/comments/basic/object-accessor-computed/input.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
({ /* 1 */ set /* 2 */ [ /* 3 */f/* 4 */] /* 5 */ (/* 6 */ a /* 7 */, /* 8 */) /* 9 */ {} });
|
||||
({ /* 1 */ get /* 2 */ [ /* 3 */f/* 4 */] /* 5 */ (/* 6 */) /* 7 */ {} });
|
||||
({ get /* 1 */ [f] () {} });
|
||||
325
packages/babel-parser/test/fixtures/comments/basic/object-accessor-computed/output.json
vendored
Normal file
325
packages/babel-parser/test/fixtures/comments/basic/object-accessor-computed/output.json
vendored
Normal file
@ -0,0 +1,325 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":197,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":28}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":197,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":28}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":0,"end":93,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":93}},
|
||||
"expression": {
|
||||
"type": "ObjectExpression",
|
||||
"start":1,"end":91,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":91}},
|
||||
"extra": {
|
||||
"parenthesized": true,
|
||||
"parenStart": 0
|
||||
},
|
||||
"properties": [
|
||||
{
|
||||
"type": "ObjectMethod",
|
||||
"start":11,"end":89,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":89}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":3,"end":10,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":10}}
|
||||
}
|
||||
],
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":15,"end":22,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":22}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":42,"end":49,"loc":{"start":{"line":1,"column":42},"end":{"line":1,"column":49}}
|
||||
}
|
||||
],
|
||||
"method": false,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":32,"end":33,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":33},"identifierName":"f"},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":25,"end":32,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":32}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":33,"end":40,"loc":{"start":{"line":1,"column":33},"end":{"line":1,"column":40}}
|
||||
}
|
||||
],
|
||||
"name": "f"
|
||||
},
|
||||
"computed": true,
|
||||
"kind": "set",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [
|
||||
{
|
||||
"type": "Identifier",
|
||||
"start":59,"end":60,"loc":{"start":{"line":1,"column":59},"end":{"line":1,"column":60},"identifierName":"a"},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 6 ",
|
||||
"start":51,"end":58,"loc":{"start":{"line":1,"column":51},"end":{"line":1,"column":58}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 7 ",
|
||||
"start":61,"end":68,"loc":{"start":{"line":1,"column":61},"end":{"line":1,"column":68}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 8 ",
|
||||
"start":70,"end":77,"loc":{"start":{"line":1,"column":70},"end":{"line":1,"column":77}}
|
||||
}
|
||||
],
|
||||
"name": "a"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":87,"end":89,"loc":{"start":{"line":1,"column":87},"end":{"line":1,"column":89}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 9 ",
|
||||
"start":79,"end":86,"loc":{"start":{"line":1,"column":79},"end":{"line":1,"column":86}}
|
||||
}
|
||||
],
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":94,"end":168,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":74}},
|
||||
"expression": {
|
||||
"type": "ObjectExpression",
|
||||
"start":95,"end":166,"loc":{"start":{"line":2,"column":1},"end":{"line":2,"column":72}},
|
||||
"extra": {
|
||||
"parenthesized": true,
|
||||
"parenStart": 94
|
||||
},
|
||||
"properties": [
|
||||
{
|
||||
"type": "ObjectMethod",
|
||||
"start":105,"end":164,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":70}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":97,"end":104,"loc":{"start":{"line":2,"column":3},"end":{"line":2,"column":10}}
|
||||
}
|
||||
],
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":109,"end":116,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":22}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":136,"end":143,"loc":{"start":{"line":2,"column":42},"end":{"line":2,"column":49}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 6 ",
|
||||
"start":145,"end":152,"loc":{"start":{"line":2,"column":51},"end":{"line":2,"column":58}}
|
||||
}
|
||||
],
|
||||
"method": false,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":126,"end":127,"loc":{"start":{"line":2,"column":32},"end":{"line":2,"column":33},"identifierName":"f"},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":119,"end":126,"loc":{"start":{"line":2,"column":25},"end":{"line":2,"column":32}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":127,"end":134,"loc":{"start":{"line":2,"column":33},"end":{"line":2,"column":40}}
|
||||
}
|
||||
],
|
||||
"name": "f"
|
||||
},
|
||||
"computed": true,
|
||||
"kind": "get",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":162,"end":164,"loc":{"start":{"line":2,"column":68},"end":{"line":2,"column":70}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 7 ",
|
||||
"start":154,"end":161,"loc":{"start":{"line":2,"column":60},"end":{"line":2,"column":67}}
|
||||
}
|
||||
],
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":169,"end":197,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":28}},
|
||||
"expression": {
|
||||
"type": "ObjectExpression",
|
||||
"start":170,"end":195,"loc":{"start":{"line":3,"column":1},"end":{"line":3,"column":26}},
|
||||
"extra": {
|
||||
"parenthesized": true,
|
||||
"parenStart": 169
|
||||
},
|
||||
"properties": [
|
||||
{
|
||||
"type": "ObjectMethod",
|
||||
"start":172,"end":193,"loc":{"start":{"line":3,"column":3},"end":{"line":3,"column":24}},
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":176,"end":183,"loc":{"start":{"line":3,"column":7},"end":{"line":3,"column":14}}
|
||||
}
|
||||
],
|
||||
"method": false,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":185,"end":186,"loc":{"start":{"line":3,"column":16},"end":{"line":3,"column":17},"identifierName":"f"},
|
||||
"name": "f"
|
||||
},
|
||||
"computed": true,
|
||||
"kind": "get",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":191,"end":193,"loc":{"start":{"line":3,"column":22},"end":{"line":3,"column":24}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
},
|
||||
"comments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":3,"end":10,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":10}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":15,"end":22,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":22}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":25,"end":32,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":32}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":33,"end":40,"loc":{"start":{"line":1,"column":33},"end":{"line":1,"column":40}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":42,"end":49,"loc":{"start":{"line":1,"column":42},"end":{"line":1,"column":49}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 6 ",
|
||||
"start":51,"end":58,"loc":{"start":{"line":1,"column":51},"end":{"line":1,"column":58}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 7 ",
|
||||
"start":61,"end":68,"loc":{"start":{"line":1,"column":61},"end":{"line":1,"column":68}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 8 ",
|
||||
"start":70,"end":77,"loc":{"start":{"line":1,"column":70},"end":{"line":1,"column":77}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 9 ",
|
||||
"start":79,"end":86,"loc":{"start":{"line":1,"column":79},"end":{"line":1,"column":86}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":97,"end":104,"loc":{"start":{"line":2,"column":3},"end":{"line":2,"column":10}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":109,"end":116,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":22}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":119,"end":126,"loc":{"start":{"line":2,"column":25},"end":{"line":2,"column":32}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":127,"end":134,"loc":{"start":{"line":2,"column":33},"end":{"line":2,"column":40}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":136,"end":143,"loc":{"start":{"line":2,"column":42},"end":{"line":2,"column":49}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 6 ",
|
||||
"start":145,"end":152,"loc":{"start":{"line":2,"column":51},"end":{"line":2,"column":58}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 7 ",
|
||||
"start":154,"end":161,"loc":{"start":{"line":2,"column":60},"end":{"line":2,"column":67}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":176,"end":183,"loc":{"start":{"line":3,"column":7},"end":{"line":3,"column":14}}
|
||||
}
|
||||
]
|
||||
}
|
||||
2
packages/babel-parser/test/fixtures/comments/basic/object-method-async-generator/input.js
vendored
Normal file
2
packages/babel-parser/test/fixtures/comments/basic/object-method-async-generator/input.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
({ /* 1 */ async /* 2 */ * /* 3 */ f /* 4 */ (/* 5 */ a /* 6 */, /* 7 */) /* 8 */ {} })
|
||||
({ async /* 1 */ *f () {} });
|
||||
197
packages/babel-parser/test/fixtures/comments/basic/object-method-async-generator/output.json
vendored
Normal file
197
packages/babel-parser/test/fixtures/comments/basic/object-method-async-generator/output.json
vendored
Normal file
@ -0,0 +1,197 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":117,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":29}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":117,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":29}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":0,"end":117,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":29}},
|
||||
"expression": {
|
||||
"type": "CallExpression",
|
||||
"start":0,"end":116,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":28}},
|
||||
"callee": {
|
||||
"type": "ObjectExpression",
|
||||
"start":1,"end":86,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":86}},
|
||||
"extra": {
|
||||
"parenthesized": true,
|
||||
"parenStart": 0
|
||||
},
|
||||
"properties": [
|
||||
{
|
||||
"type": "ObjectMethod",
|
||||
"start":11,"end":84,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":84}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":3,"end":10,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":10}}
|
||||
}
|
||||
],
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":17,"end":24,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":24}}
|
||||
}
|
||||
],
|
||||
"method": true,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":35,"end":36,"loc":{"start":{"line":1,"column":35},"end":{"line":1,"column":36},"identifierName":"f"},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":27,"end":34,"loc":{"start":{"line":1,"column":27},"end":{"line":1,"column":34}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":37,"end":44,"loc":{"start":{"line":1,"column":37},"end":{"line":1,"column":44}}
|
||||
}
|
||||
],
|
||||
"name": "f"
|
||||
},
|
||||
"computed": false,
|
||||
"kind": "method",
|
||||
"id": null,
|
||||
"generator": true,
|
||||
"async": true,
|
||||
"params": [
|
||||
{
|
||||
"type": "Identifier",
|
||||
"start":54,"end":55,"loc":{"start":{"line":1,"column":54},"end":{"line":1,"column":55},"identifierName":"a"},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":46,"end":53,"loc":{"start":{"line":1,"column":46},"end":{"line":1,"column":53}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 6 ",
|
||||
"start":56,"end":63,"loc":{"start":{"line":1,"column":56},"end":{"line":1,"column":63}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 7 ",
|
||||
"start":65,"end":72,"loc":{"start":{"line":1,"column":65},"end":{"line":1,"column":72}}
|
||||
}
|
||||
],
|
||||
"name": "a"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":82,"end":84,"loc":{"start":{"line":1,"column":82},"end":{"line":1,"column":84}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 8 ",
|
||||
"start":74,"end":81,"loc":{"start":{"line":1,"column":74},"end":{"line":1,"column":81}}
|
||||
}
|
||||
],
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"arguments": [
|
||||
{
|
||||
"type": "ObjectExpression",
|
||||
"start":89,"end":115,"loc":{"start":{"line":2,"column":1},"end":{"line":2,"column":27}},
|
||||
"properties": [
|
||||
{
|
||||
"type": "ObjectMethod",
|
||||
"start":91,"end":113,"loc":{"start":{"line":2,"column":3},"end":{"line":2,"column":25}},
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":97,"end":104,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":16}}
|
||||
}
|
||||
],
|
||||
"method": true,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":106,"end":107,"loc":{"start":{"line":2,"column":18},"end":{"line":2,"column":19},"identifierName":"f"},
|
||||
"name": "f"
|
||||
},
|
||||
"computed": false,
|
||||
"kind": "method",
|
||||
"id": null,
|
||||
"generator": true,
|
||||
"async": true,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":111,"end":113,"loc":{"start":{"line":2,"column":23},"end":{"line":2,"column":25}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
},
|
||||
"comments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":3,"end":10,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":10}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":17,"end":24,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":24}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":27,"end":34,"loc":{"start":{"line":1,"column":27},"end":{"line":1,"column":34}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":37,"end":44,"loc":{"start":{"line":1,"column":37},"end":{"line":1,"column":44}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":46,"end":53,"loc":{"start":{"line":1,"column":46},"end":{"line":1,"column":53}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 6 ",
|
||||
"start":56,"end":63,"loc":{"start":{"line":1,"column":56},"end":{"line":1,"column":63}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 7 ",
|
||||
"start":65,"end":72,"loc":{"start":{"line":1,"column":65},"end":{"line":1,"column":72}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 8 ",
|
||||
"start":74,"end":81,"loc":{"start":{"line":1,"column":74},"end":{"line":1,"column":81}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":97,"end":104,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":16}}
|
||||
}
|
||||
]
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/comments/basic/object-method/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/comments/basic/object-method/input.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
(/* 1 */ { /* 2 */ f /* 3 */ (/* 4 */ a /* 5 */, /* 6 */) /* 7 */ { /* 8 */ } /* 9 */ } /* 10 */);
|
||||
175
packages/babel-parser/test/fixtures/comments/basic/object-method/output.json
vendored
Normal file
175
packages/babel-parser/test/fixtures/comments/basic/object-method/output.json
vendored
Normal file
@ -0,0 +1,175 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":98,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":98}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":98,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":98}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":0,"end":98,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":98}},
|
||||
"expression": {
|
||||
"type": "ObjectExpression",
|
||||
"start":9,"end":87,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":87}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":1,"end":8,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":8}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 10 ",
|
||||
"start":88,"end":96,"loc":{"start":{"line":1,"column":88},"end":{"line":1,"column":96}}
|
||||
}
|
||||
],
|
||||
"extra": {
|
||||
"parenthesized": true,
|
||||
"parenStart": 0
|
||||
},
|
||||
"properties": [
|
||||
{
|
||||
"type": "ObjectMethod",
|
||||
"start":19,"end":77,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":77}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":11,"end":18,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":18}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 9 ",
|
||||
"start":78,"end":85,"loc":{"start":{"line":1,"column":78},"end":{"line":1,"column":85}}
|
||||
}
|
||||
],
|
||||
"method": true,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":19,"end":20,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":20},"identifierName":"f"},
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":21,"end":28,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":28}}
|
||||
}
|
||||
],
|
||||
"name": "f"
|
||||
},
|
||||
"computed": false,
|
||||
"kind": "method",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [
|
||||
{
|
||||
"type": "Identifier",
|
||||
"start":38,"end":39,"loc":{"start":{"line":1,"column":38},"end":{"line":1,"column":39},"identifierName":"a"},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":30,"end":37,"loc":{"start":{"line":1,"column":30},"end":{"line":1,"column":37}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":40,"end":47,"loc":{"start":{"line":1,"column":40},"end":{"line":1,"column":47}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 6 ",
|
||||
"start":49,"end":56,"loc":{"start":{"line":1,"column":49},"end":{"line":1,"column":56}}
|
||||
}
|
||||
],
|
||||
"name": "a"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":66,"end":77,"loc":{"start":{"line":1,"column":66},"end":{"line":1,"column":77}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 7 ",
|
||||
"start":58,"end":65,"loc":{"start":{"line":1,"column":58},"end":{"line":1,"column":65}}
|
||||
}
|
||||
],
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 8 ",
|
||||
"start":68,"end":75,"loc":{"start":{"line":1,"column":68},"end":{"line":1,"column":75}}
|
||||
}
|
||||
],
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
},
|
||||
"comments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":1,"end":8,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":8}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":11,"end":18,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":18}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":21,"end":28,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":28}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":30,"end":37,"loc":{"start":{"line":1,"column":30},"end":{"line":1,"column":37}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":40,"end":47,"loc":{"start":{"line":1,"column":40},"end":{"line":1,"column":47}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 6 ",
|
||||
"start":49,"end":56,"loc":{"start":{"line":1,"column":49},"end":{"line":1,"column":56}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 7 ",
|
||||
"start":58,"end":65,"loc":{"start":{"line":1,"column":58},"end":{"line":1,"column":65}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 8 ",
|
||||
"start":68,"end":75,"loc":{"start":{"line":1,"column":68},"end":{"line":1,"column":75}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 9 ",
|
||||
"start":78,"end":85,"loc":{"start":{"line":1,"column":78},"end":{"line":1,"column":85}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 10 ",
|
||||
"start":88,"end":96,"loc":{"start":{"line":1,"column":88},"end":{"line":1,"column":96}}
|
||||
}
|
||||
]
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/comments/basic/sequence-expression/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/comments/basic/sequence-expression/input.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
/* 1 */ (/* 2 */ ( /* 3 */ a /* 4 */, /* 5 */ b /* 6 */ ) /* 7 */ ) /* 8 */; /* 9 */
|
||||
145
packages/babel-parser/test/fixtures/comments/basic/sequence-expression/output.json
vendored
Normal file
145
packages/babel-parser/test/fixtures/comments/basic/sequence-expression/output.json
vendored
Normal file
@ -0,0 +1,145 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":84,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":84}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":84,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":84}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":8,"end":76,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":76}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":0,"end":7,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":7}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 9 ",
|
||||
"start":77,"end":84,"loc":{"start":{"line":1,"column":77},"end":{"line":1,"column":84}}
|
||||
}
|
||||
],
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":9,"end":16,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":16}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 8 ",
|
||||
"start":68,"end":75,"loc":{"start":{"line":1,"column":68},"end":{"line":1,"column":75}}
|
||||
}
|
||||
],
|
||||
"expression": {
|
||||
"type": "SequenceExpression",
|
||||
"start":27,"end":47,"loc":{"start":{"line":1,"column":27},"end":{"line":1,"column":47}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":19,"end":26,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":26}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 7 ",
|
||||
"start":58,"end":65,"loc":{"start":{"line":1,"column":58},"end":{"line":1,"column":65}}
|
||||
}
|
||||
],
|
||||
"extra": {
|
||||
"parenthesized": true,
|
||||
"parenStart": 8
|
||||
},
|
||||
"expressions": [
|
||||
{
|
||||
"type": "Identifier",
|
||||
"start":27,"end":28,"loc":{"start":{"line":1,"column":27},"end":{"line":1,"column":28},"identifierName":"a"},
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":29,"end":36,"loc":{"start":{"line":1,"column":29},"end":{"line":1,"column":36}}
|
||||
}
|
||||
],
|
||||
"name": "a"
|
||||
},
|
||||
{
|
||||
"type": "Identifier",
|
||||
"start":46,"end":47,"loc":{"start":{"line":1,"column":46},"end":{"line":1,"column":47},"identifierName":"b"},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":38,"end":45,"loc":{"start":{"line":1,"column":38},"end":{"line":1,"column":45}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 6 ",
|
||||
"start":48,"end":55,"loc":{"start":{"line":1,"column":48},"end":{"line":1,"column":55}}
|
||||
}
|
||||
],
|
||||
"name": "b"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
},
|
||||
"comments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":0,"end":7,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":7}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":9,"end":16,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":16}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 3 ",
|
||||
"start":19,"end":26,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":26}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 4 ",
|
||||
"start":29,"end":36,"loc":{"start":{"line":1,"column":29},"end":{"line":1,"column":36}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 5 ",
|
||||
"start":38,"end":45,"loc":{"start":{"line":1,"column":38},"end":{"line":1,"column":45}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 6 ",
|
||||
"start":48,"end":55,"loc":{"start":{"line":1,"column":48},"end":{"line":1,"column":55}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 7 ",
|
||||
"start":58,"end":65,"loc":{"start":{"line":1,"column":58},"end":{"line":1,"column":65}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 8 ",
|
||||
"start":68,"end":75,"loc":{"start":{"line":1,"column":68},"end":{"line":1,"column":75}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 9 ",
|
||||
"start":77,"end":84,"loc":{"start":{"line":1,"column":77},"end":{"line":1,"column":84}}
|
||||
}
|
||||
]
|
||||
}
|
||||
6
packages/babel-parser/test/fixtures/comments/basic/switch-case/input.js
vendored
Normal file
6
packages/babel-parser/test/fixtures/comments/basic/switch-case/input.js
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
/*-1*/ foo /*0*/ : /*1*/ switch /*2*/ ( /*3*/ false /*4*/ ) /*5*/ {
|
||||
/*6*/ case /*7*/ false /*8*/ : /*9*/
|
||||
break /*10*/ foo /*11*/ ;
|
||||
/*12*/ default /*13*/ : /*14*/
|
||||
case /*15*/ false /*16*/ : /*17*/ { /*18*/ } /*19*/
|
||||
}
|
||||
342
packages/babel-parser/test/fixtures/comments/basic/switch-case/output.json
vendored
Normal file
342
packages/babel-parser/test/fixtures/comments/basic/switch-case/output.json
vendored
Normal file
@ -0,0 +1,342 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":233,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":3}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":233,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":3}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "LabeledStatement",
|
||||
"start":7,"end":233,"loc":{"start":{"line":1,"column":7},"end":{"line":6,"column":3}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "-1",
|
||||
"start":0,"end":6,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":6}}
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"type": "SwitchStatement",
|
||||
"start":25,"end":233,"loc":{"start":{"line":1,"column":25},"end":{"line":6,"column":3}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "1",
|
||||
"start":19,"end":24,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":24}}
|
||||
}
|
||||
],
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "2",
|
||||
"start":32,"end":37,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":37}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "5",
|
||||
"start":60,"end":65,"loc":{"start":{"line":1,"column":60},"end":{"line":1,"column":65}}
|
||||
}
|
||||
],
|
||||
"discriminant": {
|
||||
"type": "BooleanLiteral",
|
||||
"start":46,"end":51,"loc":{"start":{"line":1,"column":46},"end":{"line":1,"column":51}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "3",
|
||||
"start":40,"end":45,"loc":{"start":{"line":1,"column":40},"end":{"line":1,"column":45}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "4",
|
||||
"start":52,"end":57,"loc":{"start":{"line":1,"column":52},"end":{"line":1,"column":57}}
|
||||
}
|
||||
],
|
||||
"value": false
|
||||
},
|
||||
"cases": [
|
||||
{
|
||||
"type": "SwitchCase",
|
||||
"start":78,"end":138,"loc":{"start":{"line":2,"column":10},"end":{"line":3,"column":29}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "6",
|
||||
"start":72,"end":77,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":9}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "12",
|
||||
"start":143,"end":149,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":10}}
|
||||
}
|
||||
],
|
||||
"consequent": [
|
||||
{
|
||||
"type": "BreakStatement",
|
||||
"start":113,"end":138,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":29}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "9",
|
||||
"start":103,"end":108,"loc":{"start":{"line":2,"column":35},"end":{"line":2,"column":40}}
|
||||
}
|
||||
],
|
||||
"label": {
|
||||
"type": "Identifier",
|
||||
"start":126,"end":129,"loc":{"start":{"line":3,"column":17},"end":{"line":3,"column":20},"identifierName":"foo"},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "10",
|
||||
"start":119,"end":125,"loc":{"start":{"line":3,"column":10},"end":{"line":3,"column":16}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "11",
|
||||
"start":130,"end":136,"loc":{"start":{"line":3,"column":21},"end":{"line":3,"column":27}}
|
||||
}
|
||||
],
|
||||
"name": "foo"
|
||||
}
|
||||
}
|
||||
],
|
||||
"test": {
|
||||
"type": "BooleanLiteral",
|
||||
"start":89,"end":94,"loc":{"start":{"line":2,"column":21},"end":{"line":2,"column":26}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "7",
|
||||
"start":83,"end":88,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":20}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "8",
|
||||
"start":95,"end":100,"loc":{"start":{"line":2,"column":27},"end":{"line":2,"column":32}}
|
||||
}
|
||||
],
|
||||
"value": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "SwitchCase",
|
||||
"start":150,"end":166,"loc":{"start":{"line":4,"column":11},"end":{"line":4,"column":27}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "12",
|
||||
"start":143,"end":149,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":10}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "14",
|
||||
"start":167,"end":173,"loc":{"start":{"line":4,"column":28},"end":{"line":4,"column":34}}
|
||||
}
|
||||
],
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "13",
|
||||
"start":158,"end":164,"loc":{"start":{"line":4,"column":19},"end":{"line":4,"column":25}}
|
||||
}
|
||||
],
|
||||
"consequent": [],
|
||||
"test": null
|
||||
},
|
||||
{
|
||||
"type": "SwitchCase",
|
||||
"start":178,"end":222,"loc":{"start":{"line":5,"column":4},"end":{"line":5,"column":48}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "14",
|
||||
"start":167,"end":173,"loc":{"start":{"line":4,"column":28},"end":{"line":4,"column":34}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "19",
|
||||
"start":223,"end":229,"loc":{"start":{"line":5,"column":49},"end":{"line":5,"column":55}}
|
||||
}
|
||||
],
|
||||
"consequent": [
|
||||
{
|
||||
"type": "BlockStatement",
|
||||
"start":212,"end":222,"loc":{"start":{"line":5,"column":38},"end":{"line":5,"column":48}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "17",
|
||||
"start":205,"end":211,"loc":{"start":{"line":5,"column":31},"end":{"line":5,"column":37}}
|
||||
}
|
||||
],
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "18",
|
||||
"start":214,"end":220,"loc":{"start":{"line":5,"column":40},"end":{"line":5,"column":46}}
|
||||
}
|
||||
],
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
],
|
||||
"test": {
|
||||
"type": "BooleanLiteral",
|
||||
"start":190,"end":195,"loc":{"start":{"line":5,"column":16},"end":{"line":5,"column":21}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "15",
|
||||
"start":183,"end":189,"loc":{"start":{"line":5,"column":9},"end":{"line":5,"column":15}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "16",
|
||||
"start":196,"end":202,"loc":{"start":{"line":5,"column":22},"end":{"line":5,"column":28}}
|
||||
}
|
||||
],
|
||||
"value": false
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"label": {
|
||||
"type": "Identifier",
|
||||
"start":7,"end":10,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":10},"identifierName":"foo"},
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "0",
|
||||
"start":11,"end":16,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":16}}
|
||||
}
|
||||
],
|
||||
"name": "foo"
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
},
|
||||
"comments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "-1",
|
||||
"start":0,"end":6,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":6}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "0",
|
||||
"start":11,"end":16,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":16}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "1",
|
||||
"start":19,"end":24,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":24}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "2",
|
||||
"start":32,"end":37,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":37}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "3",
|
||||
"start":40,"end":45,"loc":{"start":{"line":1,"column":40},"end":{"line":1,"column":45}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "4",
|
||||
"start":52,"end":57,"loc":{"start":{"line":1,"column":52},"end":{"line":1,"column":57}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "5",
|
||||
"start":60,"end":65,"loc":{"start":{"line":1,"column":60},"end":{"line":1,"column":65}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "6",
|
||||
"start":72,"end":77,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":9}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "7",
|
||||
"start":83,"end":88,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":20}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "8",
|
||||
"start":95,"end":100,"loc":{"start":{"line":2,"column":27},"end":{"line":2,"column":32}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "9",
|
||||
"start":103,"end":108,"loc":{"start":{"line":2,"column":35},"end":{"line":2,"column":40}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "10",
|
||||
"start":119,"end":125,"loc":{"start":{"line":3,"column":10},"end":{"line":3,"column":16}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "11",
|
||||
"start":130,"end":136,"loc":{"start":{"line":3,"column":21},"end":{"line":3,"column":27}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "12",
|
||||
"start":143,"end":149,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":10}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "13",
|
||||
"start":158,"end":164,"loc":{"start":{"line":4,"column":19},"end":{"line":4,"column":25}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "14",
|
||||
"start":167,"end":173,"loc":{"start":{"line":4,"column":28},"end":{"line":4,"column":34}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "15",
|
||||
"start":183,"end":189,"loc":{"start":{"line":5,"column":9},"end":{"line":5,"column":15}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "16",
|
||||
"start":196,"end":202,"loc":{"start":{"line":5,"column":22},"end":{"line":5,"column":28}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "17",
|
||||
"start":205,"end":211,"loc":{"start":{"line":5,"column":31},"end":{"line":5,"column":37}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "18",
|
||||
"start":214,"end":220,"loc":{"start":{"line":5,"column":40},"end":{"line":5,"column":46}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "19",
|
||||
"start":223,"end":229,"loc":{"start":{"line":5,"column":49},"end":{"line":5,"column":55}}
|
||||
}
|
||||
]
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/comments/basic/switch-no-case-comment/input.js
vendored
Executable file
1
packages/babel-parser/test/fixtures/comments/basic/switch-no-case-comment/input.js
vendored
Executable file
@ -0,0 +1 @@
|
||||
switch (c)/*1*/ { /*2*/ } /*3*/
|
||||
59
packages/babel-parser/test/fixtures/comments/basic/switch-no-case-comment/output.json
vendored
Normal file
59
packages/babel-parser/test/fixtures/comments/basic/switch-no-case-comment/output.json
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":31,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":31}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":31,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":31}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "SwitchStatement",
|
||||
"start":0,"end":25,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":25}},
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "3",
|
||||
"start":26,"end":31,"loc":{"start":{"line":1,"column":26},"end":{"line":1,"column":31}}
|
||||
}
|
||||
],
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "1",
|
||||
"start":10,"end":15,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":15}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "2",
|
||||
"start":18,"end":23,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":23}}
|
||||
}
|
||||
],
|
||||
"discriminant": {
|
||||
"type": "Identifier",
|
||||
"start":8,"end":9,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":9},"identifierName":"c"},
|
||||
"name": "c"
|
||||
},
|
||||
"cases": []
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
},
|
||||
"comments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "1",
|
||||
"start":10,"end":15,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":15}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "2",
|
||||
"start":18,"end":23,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":23}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "3",
|
||||
"start":26,"end":31,"loc":{"start":{"line":1,"column":26},"end":{"line":1,"column":31}}
|
||||
}
|
||||
]
|
||||
}
|
||||
4
packages/babel-parser/test/fixtures/comments/basic/try-statement/input.js
vendored
Normal file
4
packages/babel-parser/test/fixtures/comments/basic/try-statement/input.js
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
/*1*/ try /*2*/ {
|
||||
/*3*/ throw /*4*/ "no" /*5*/;
|
||||
/*6*/} /*7*/ catch /*8*/ ( /*9*/ e /*10*/ ) /*11*/ { /*12*/
|
||||
} /*13*/ finally /*14*/ { /*15*/ } /*16*/
|
||||
259
packages/babel-parser/test/fixtures/comments/basic/try-statement/output.json
vendored
Normal file
259
packages/babel-parser/test/fixtures/comments/basic/try-statement/output.json
vendored
Normal file
@ -0,0 +1,259 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":153,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":41}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":153,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":41}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "TryStatement",
|
||||
"start":6,"end":146,"loc":{"start":{"line":1,"column":6},"end":{"line":4,"column":34}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "1",
|
||||
"start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "16",
|
||||
"start":147,"end":153,"loc":{"start":{"line":4,"column":35},"end":{"line":4,"column":41}}
|
||||
}
|
||||
],
|
||||
"block": {
|
||||
"type": "BlockStatement",
|
||||
"start":16,"end":58,"loc":{"start":{"line":1,"column":16},"end":{"line":3,"column":6}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "2",
|
||||
"start":10,"end":15,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":15}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "7",
|
||||
"start":59,"end":64,"loc":{"start":{"line":3,"column":7},"end":{"line":3,"column":12}}
|
||||
}
|
||||
],
|
||||
"body": [
|
||||
{
|
||||
"type": "ThrowStatement",
|
||||
"start":28,"end":51,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":33}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "3",
|
||||
"start":22,"end":27,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":9}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "6",
|
||||
"start":52,"end":57,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":5}}
|
||||
}
|
||||
],
|
||||
"argument": {
|
||||
"type": "StringLiteral",
|
||||
"start":40,"end":44,"loc":{"start":{"line":2,"column":22},"end":{"line":2,"column":26}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "4",
|
||||
"start":34,"end":39,"loc":{"start":{"line":2,"column":16},"end":{"line":2,"column":21}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "5",
|
||||
"start":45,"end":50,"loc":{"start":{"line":2,"column":27},"end":{"line":2,"column":32}}
|
||||
}
|
||||
],
|
||||
"extra": {
|
||||
"rawValue": "no",
|
||||
"raw": "\"no\""
|
||||
},
|
||||
"value": "no"
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
},
|
||||
"handler": {
|
||||
"type": "CatchClause",
|
||||
"start":65,"end":113,"loc":{"start":{"line":3,"column":13},"end":{"line":4,"column":1}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "7",
|
||||
"start":59,"end":64,"loc":{"start":{"line":3,"column":7},"end":{"line":3,"column":12}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "13",
|
||||
"start":114,"end":120,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":8}}
|
||||
}
|
||||
],
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "8",
|
||||
"start":71,"end":76,"loc":{"start":{"line":3,"column":19},"end":{"line":3,"column":24}}
|
||||
}
|
||||
],
|
||||
"param": {
|
||||
"type": "Identifier",
|
||||
"start":85,"end":86,"loc":{"start":{"line":3,"column":33},"end":{"line":3,"column":34},"identifierName":"e"},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "9",
|
||||
"start":79,"end":84,"loc":{"start":{"line":3,"column":27},"end":{"line":3,"column":32}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "10",
|
||||
"start":87,"end":93,"loc":{"start":{"line":3,"column":35},"end":{"line":3,"column":41}}
|
||||
}
|
||||
],
|
||||
"name": "e"
|
||||
},
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":103,"end":113,"loc":{"start":{"line":3,"column":51},"end":{"line":4,"column":1}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "11",
|
||||
"start":96,"end":102,"loc":{"start":{"line":3,"column":44},"end":{"line":3,"column":50}}
|
||||
}
|
||||
],
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "12",
|
||||
"start":105,"end":111,"loc":{"start":{"line":3,"column":53},"end":{"line":3,"column":59}}
|
||||
}
|
||||
],
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
},
|
||||
"finalizer": {
|
||||
"type": "BlockStatement",
|
||||
"start":136,"end":146,"loc":{"start":{"line":4,"column":24},"end":{"line":4,"column":34}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "14",
|
||||
"start":129,"end":135,"loc":{"start":{"line":4,"column":17},"end":{"line":4,"column":23}}
|
||||
}
|
||||
],
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "15",
|
||||
"start":138,"end":144,"loc":{"start":{"line":4,"column":26},"end":{"line":4,"column":32}}
|
||||
}
|
||||
],
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
},
|
||||
"comments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "1",
|
||||
"start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "2",
|
||||
"start":10,"end":15,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":15}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "3",
|
||||
"start":22,"end":27,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":9}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "4",
|
||||
"start":34,"end":39,"loc":{"start":{"line":2,"column":16},"end":{"line":2,"column":21}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "5",
|
||||
"start":45,"end":50,"loc":{"start":{"line":2,"column":27},"end":{"line":2,"column":32}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "6",
|
||||
"start":52,"end":57,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":5}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "7",
|
||||
"start":59,"end":64,"loc":{"start":{"line":3,"column":7},"end":{"line":3,"column":12}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "8",
|
||||
"start":71,"end":76,"loc":{"start":{"line":3,"column":19},"end":{"line":3,"column":24}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "9",
|
||||
"start":79,"end":84,"loc":{"start":{"line":3,"column":27},"end":{"line":3,"column":32}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "10",
|
||||
"start":87,"end":93,"loc":{"start":{"line":3,"column":35},"end":{"line":3,"column":41}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "11",
|
||||
"start":96,"end":102,"loc":{"start":{"line":3,"column":44},"end":{"line":3,"column":50}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "12",
|
||||
"start":105,"end":111,"loc":{"start":{"line":3,"column":53},"end":{"line":3,"column":59}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "13",
|
||||
"start":114,"end":120,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":8}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "14",
|
||||
"start":129,"end":135,"loc":{"start":{"line":4,"column":17},"end":{"line":4,"column":23}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "15",
|
||||
"start":138,"end":144,"loc":{"start":{"line":4,"column":26},"end":{"line":4,"column":32}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "16",
|
||||
"start":147,"end":153,"loc":{"start":{"line":4,"column":35},"end":{"line":4,"column":41}}
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -16,27 +16,20 @@
|
||||
"left": {
|
||||
"type": "Identifier",
|
||||
"start":0,"end":3,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":3},"identifierName":"foo"},
|
||||
"name": "foo",
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentLine",
|
||||
"value": "bar",
|
||||
"start":4,"end":11,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":11}}
|
||||
}
|
||||
]
|
||||
],
|
||||
"name": "foo"
|
||||
},
|
||||
"operator": "+",
|
||||
"right": {
|
||||
"type": "Identifier",
|
||||
"start":13,"end":16,"loc":{"start":{"line":2,"column":1},"end":{"line":2,"column":4},"identifierName":"baz"},
|
||||
"name": "baz",
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentLine",
|
||||
"value": "bar",
|
||||
"start":4,"end":11,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":11}}
|
||||
}
|
||||
]
|
||||
"name": "baz"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,20 +10,17 @@
|
||||
{
|
||||
"type": "ExportNamedDeclaration",
|
||||
"start":0,"end":76,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":24}},
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " Four ",
|
||||
"start":54,"end":64,"loc":{"start":{"line":5,"column":2},"end":{"line":5,"column":12}}
|
||||
}
|
||||
],
|
||||
"specifiers": [
|
||||
{
|
||||
"type": "ExportSpecifier",
|
||||
"start":21,"end":24,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":15}},
|
||||
"local": {
|
||||
"type": "Identifier",
|
||||
"start":21,"end":24,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":15},"identifierName":"Foo"},
|
||||
"name": "Foo"
|
||||
},
|
||||
"exported": {
|
||||
"type": "Identifier",
|
||||
"start":21,"end":24,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":15},"identifierName":"Foo"},
|
||||
"name": "Foo"
|
||||
},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
@ -41,13 +38,18 @@
|
||||
"type": "CommentBlock",
|
||||
"value": " Three ",
|
||||
"start":40,"end":51,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":13}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " Four ",
|
||||
"start":54,"end":64,"loc":{"start":{"line":5,"column":2},"end":{"line":5,"column":12}}
|
||||
}
|
||||
]
|
||||
],
|
||||
"local": {
|
||||
"type": "Identifier",
|
||||
"start":21,"end":24,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":15},"identifierName":"Foo"},
|
||||
"name": "Foo"
|
||||
},
|
||||
"exported": {
|
||||
"type": "Identifier",
|
||||
"start":21,"end":24,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":15},"identifierName":"Foo"},
|
||||
"name": "Foo"
|
||||
}
|
||||
}
|
||||
],
|
||||
"source": {
|
||||
|
||||
@ -10,20 +10,17 @@
|
||||
{
|
||||
"type": "ImportDeclaration",
|
||||
"start":0,"end":76,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":24}},
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " Four ",
|
||||
"start":54,"end":64,"loc":{"start":{"line":5,"column":2},"end":{"line":5,"column":12}}
|
||||
}
|
||||
],
|
||||
"specifiers": [
|
||||
{
|
||||
"type": "ImportSpecifier",
|
||||
"start":21,"end":24,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":15}},
|
||||
"imported": {
|
||||
"type": "Identifier",
|
||||
"start":21,"end":24,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":15},"identifierName":"Foo"},
|
||||
"name": "Foo"
|
||||
},
|
||||
"local": {
|
||||
"type": "Identifier",
|
||||
"start":21,"end":24,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":15},"identifierName":"Foo"},
|
||||
"name": "Foo"
|
||||
},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
@ -41,13 +38,18 @@
|
||||
"type": "CommentBlock",
|
||||
"value": " Three ",
|
||||
"start":40,"end":51,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":13}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " Four ",
|
||||
"start":54,"end":64,"loc":{"start":{"line":5,"column":2},"end":{"line":5,"column":12}}
|
||||
}
|
||||
]
|
||||
],
|
||||
"imported": {
|
||||
"type": "Identifier",
|
||||
"start":21,"end":24,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":15},"identifierName":"Foo"},
|
||||
"name": "Foo"
|
||||
},
|
||||
"local": {
|
||||
"type": "Identifier",
|
||||
"start":21,"end":24,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":15},"identifierName":"Foo"},
|
||||
"name": "Foo"
|
||||
}
|
||||
}
|
||||
],
|
||||
"source": {
|
||||
|
||||
@ -0,0 +1 @@
|
||||
foo?.(x, /* 1 */)/* 2 */
|
||||
@ -0,0 +1,60 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":24,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":24}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":24,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":24}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":0,"end":17,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":17}},
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":17,"end":24,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":24}}
|
||||
}
|
||||
],
|
||||
"expression": {
|
||||
"type": "OptionalCallExpression",
|
||||
"start":0,"end":17,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":17}},
|
||||
"callee": {
|
||||
"type": "Identifier",
|
||||
"start":0,"end":3,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":3},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
},
|
||||
"optional": true,
|
||||
"arguments": [
|
||||
{
|
||||
"type": "Identifier",
|
||||
"start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"x"},
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":9,"end":16,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":16}}
|
||||
}
|
||||
],
|
||||
"name": "x"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
},
|
||||
"comments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":9,"end":16,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":16}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 2 ",
|
||||
"start":17,"end":24,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":24}}
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,2 @@
|
||||
#[ a,/* 1 */]
|
||||
#{ a,/* 1 */}
|
||||
@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": [["recordAndTuple", { "syntaxType": "hash" }]]
|
||||
}
|
||||
@ -0,0 +1,90 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":27,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":13}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":27,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":13}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
|
||||
"expression": {
|
||||
"type": "TupleExpression",
|
||||
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
|
||||
"extra": {
|
||||
"trailingComma": 4
|
||||
},
|
||||
"elements": [
|
||||
{
|
||||
"type": "Identifier",
|
||||
"start":3,"end":4,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":4},"identifierName":"a"},
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":5,"end":12,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":12}}
|
||||
}
|
||||
],
|
||||
"name": "a"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":14,"end":27,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":13}},
|
||||
"expression": {
|
||||
"type": "RecordExpression",
|
||||
"start":14,"end":27,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":13}},
|
||||
"extra": {
|
||||
"trailingComma": 18
|
||||
},
|
||||
"properties": [
|
||||
{
|
||||
"type": "ObjectProperty",
|
||||
"start":17,"end":18,"loc":{"start":{"line":2,"column":3},"end":{"line":2,"column":4}},
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":19,"end":26,"loc":{"start":{"line":2,"column":5},"end":{"line":2,"column":12}}
|
||||
}
|
||||
],
|
||||
"extra": {
|
||||
"shorthand": true
|
||||
},
|
||||
"method": false,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":17,"end":18,"loc":{"start":{"line":2,"column":3},"end":{"line":2,"column":4},"identifierName":"a"},
|
||||
"name": "a"
|
||||
},
|
||||
"computed": false,
|
||||
"shorthand": true,
|
||||
"value": {
|
||||
"type": "Identifier",
|
||||
"start":17,"end":18,"loc":{"start":{"line":2,"column":3},"end":{"line":2,"column":4},"identifierName":"a"},
|
||||
"name": "a"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
},
|
||||
"comments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":5,"end":12,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":12}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": " 1 ",
|
||||
"start":19,"end":26,"loc":{"start":{"line":2,"column":5},"end":{"line":2,"column":12}}
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -34,20 +34,15 @@
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":51,"end":54,"loc":{"start":{"line":1,"column":51},"end":{"line":2,"column":1}},
|
||||
"body": [],
|
||||
"directives": [],
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": ": string ",
|
||||
"start":22,"end":35,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":35}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": ": number ",
|
||||
"start":37,"end":50,"loc":{"start":{"line":1,"column":37},"end":{"line":1,"column":50}}
|
||||
}
|
||||
]
|
||||
],
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
@ -24,17 +24,24 @@
|
||||
"start":94,"end":99,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":5}}
|
||||
}
|
||||
],
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "2",
|
||||
"start":13,"end":18,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":18}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "9",
|
||||
"start":69,"end":74,"loc":{"start":{"line":1,"column":69},"end":{"line":1,"column":74}}
|
||||
}
|
||||
],
|
||||
"exportKind": "value",
|
||||
"specifiers": [
|
||||
{
|
||||
"type": "ExportSpecifier",
|
||||
"start":27,"end":28,"loc":{"start":{"line":1,"column":27},"end":{"line":1,"column":28}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "2",
|
||||
"start":13,"end":18,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":18}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "3",
|
||||
@ -46,11 +53,6 @@
|
||||
"type": "CommentBlock",
|
||||
"value": "4",
|
||||
"start":29,"end":34,"loc":{"start":{"line":1,"column":29},"end":{"line":1,"column":34}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "5",
|
||||
"start":36,"end":41,"loc":{"start":{"line":1,"column":36},"end":{"line":1,"column":41}}
|
||||
}
|
||||
],
|
||||
"local": {
|
||||
@ -67,21 +69,18 @@
|
||||
{
|
||||
"type": "ExportSpecifier",
|
||||
"start":42,"end":60,"loc":{"start":{"line":1,"column":42},"end":{"line":1,"column":60}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "5",
|
||||
"start":36,"end":41,"loc":{"start":{"line":1,"column":36},"end":{"line":1,"column":41}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "8",
|
||||
"start":61,"end":66,"loc":{"start":{"line":1,"column":61},"end":{"line":1,"column":66}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "9",
|
||||
"start":69,"end":74,"loc":{"start":{"line":1,"column":69},"end":{"line":1,"column":74}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "10",
|
||||
"start":80,"end":86,"loc":{"start":{"line":1,"column":80},"end":{"line":1,"column":86}}
|
||||
}
|
||||
],
|
||||
"local": {
|
||||
@ -100,11 +99,6 @@
|
||||
"type": "Identifier",
|
||||
"start":59,"end":60,"loc":{"start":{"line":1,"column":59},"end":{"line":1,"column":60},"identifierName":"C"},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "6",
|
||||
"start":44,"end":49,"loc":{"start":{"line":1,"column":44},"end":{"line":1,"column":49}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "7",
|
||||
@ -118,6 +112,13 @@
|
||||
"source": {
|
||||
"type": "StringLiteral",
|
||||
"start":87,"end":92,"loc":{"start":{"line":1,"column":87},"end":{"line":1,"column":92}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "10",
|
||||
"start":80,"end":86,"loc":{"start":{"line":1,"column":80},"end":{"line":1,"column":86}}
|
||||
}
|
||||
],
|
||||
"extra": {
|
||||
"rawValue": "foo",
|
||||
"raw": "\"foo\""
|
||||
@ -136,11 +137,7 @@
|
||||
"start":94,"end":99,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":5}}
|
||||
}
|
||||
],
|
||||
"exportKind": "value",
|
||||
"source": {
|
||||
"type": "StringLiteral",
|
||||
"start":132,"end":137,"loc":{"start":{"line":2,"column":38},"end":{"line":2,"column":43}},
|
||||
"leadingComments": [
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "2",
|
||||
@ -150,7 +147,13 @@
|
||||
"type": "CommentBlock",
|
||||
"value": "3",
|
||||
"start":115,"end":120,"loc":{"start":{"line":2,"column":21},"end":{"line":2,"column":26}}
|
||||
},
|
||||
}
|
||||
],
|
||||
"exportKind": "value",
|
||||
"source": {
|
||||
"type": "StringLiteral",
|
||||
"start":132,"end":137,"loc":{"start":{"line":2,"column":38},"end":{"line":2,"column":43}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "4",
|
||||
|
||||
@ -24,6 +24,18 @@
|
||||
"start":111,"end":116,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":5}}
|
||||
}
|
||||
],
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "4",
|
||||
"start":28,"end":33,"loc":{"start":{"line":1,"column":28},"end":{"line":1,"column":33}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "11",
|
||||
"start":85,"end":91,"loc":{"start":{"line":1,"column":85},"end":{"line":1,"column":91}}
|
||||
}
|
||||
],
|
||||
"importKind": "value",
|
||||
"specifiers": [
|
||||
{
|
||||
@ -53,26 +65,6 @@
|
||||
"type": "ImportSpecifier",
|
||||
"start":42,"end":43,"loc":{"start":{"line":1,"column":42},"end":{"line":1,"column":43}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "1",
|
||||
"start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "2",
|
||||
"start":13,"end":18,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":18}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "3",
|
||||
"start":21,"end":26,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":26}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "4",
|
||||
"start":28,"end":33,"loc":{"start":{"line":1,"column":28},"end":{"line":1,"column":33}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "5",
|
||||
@ -84,11 +76,6 @@
|
||||
"type": "CommentBlock",
|
||||
"value": "6",
|
||||
"start":44,"end":49,"loc":{"start":{"line":1,"column":44},"end":{"line":1,"column":49}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "7",
|
||||
"start":51,"end":56,"loc":{"start":{"line":1,"column":51},"end":{"line":1,"column":56}}
|
||||
}
|
||||
],
|
||||
"imported": {
|
||||
@ -105,21 +92,18 @@
|
||||
{
|
||||
"type": "ImportSpecifier",
|
||||
"start":57,"end":75,"loc":{"start":{"line":1,"column":57},"end":{"line":1,"column":75}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "7",
|
||||
"start":51,"end":56,"loc":{"start":{"line":1,"column":51},"end":{"line":1,"column":56}}
|
||||
}
|
||||
],
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "10",
|
||||
"start":76,"end":82,"loc":{"start":{"line":1,"column":76},"end":{"line":1,"column":82}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "11",
|
||||
"start":85,"end":91,"loc":{"start":{"line":1,"column":85},"end":{"line":1,"column":91}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "12",
|
||||
"start":97,"end":103,"loc":{"start":{"line":1,"column":97},"end":{"line":1,"column":103}}
|
||||
}
|
||||
],
|
||||
"imported": {
|
||||
@ -138,11 +122,6 @@
|
||||
"type": "Identifier",
|
||||
"start":74,"end":75,"loc":{"start":{"line":1,"column":74},"end":{"line":1,"column":75},"identifierName":"C"},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "8",
|
||||
"start":59,"end":64,"loc":{"start":{"line":1,"column":59},"end":{"line":1,"column":64}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "9",
|
||||
@ -156,6 +135,13 @@
|
||||
"source": {
|
||||
"type": "StringLiteral",
|
||||
"start":104,"end":109,"loc":{"start":{"line":1,"column":104},"end":{"line":1,"column":109}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "12",
|
||||
"start":97,"end":103,"loc":{"start":{"line":1,"column":97},"end":{"line":1,"column":103}}
|
||||
}
|
||||
],
|
||||
"extra": {
|
||||
"rawValue": "foo",
|
||||
"raw": "\"foo\""
|
||||
@ -192,15 +178,17 @@
|
||||
"start":151,"end":156,"loc":{"start":{"line":2,"column":40},"end":{"line":2,"column":45}}
|
||||
}
|
||||
],
|
||||
"local": {
|
||||
"type": "Identifier",
|
||||
"start":147,"end":150,"loc":{"start":{"line":2,"column":36},"end":{"line":2,"column":39},"identifierName":"foo"},
|
||||
"leadingComments": [
|
||||
"innerComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "3",
|
||||
"start":132,"end":137,"loc":{"start":{"line":2,"column":21},"end":{"line":2,"column":26}}
|
||||
},
|
||||
}
|
||||
],
|
||||
"local": {
|
||||
"type": "Identifier",
|
||||
"start":147,"end":150,"loc":{"start":{"line":2,"column":36},"end":{"line":2,"column":39},"identifierName":"foo"},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "4",
|
||||
@ -215,11 +203,6 @@
|
||||
"type": "StringLiteral",
|
||||
"start":168,"end":173,"loc":{"start":{"line":2,"column":57},"end":{"line":2,"column":62}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "5",
|
||||
"start":151,"end":156,"loc":{"start":{"line":2,"column":40},"end":{"line":2,"column":45}}
|
||||
},
|
||||
{
|
||||
"type": "CommentBlock",
|
||||
"value": "6",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user