Skip to content

Commit

Permalink
bugfix: ignore comment after source of import
Browse files Browse the repository at this point in the history
  • Loading branch information
mistlog committed Mar 14, 2021
1 parent 90cecae commit f30f883
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 10 deletions.
10 changes: 4 additions & 6 deletions src/parser/basic/string.tsx
Expand Up @@ -3,7 +3,7 @@ import { _ } from "../common";

export function SourceCharacter() {
return (
<any/>
<any />
)
}

Expand All @@ -13,16 +13,14 @@ export function SourceCharacter() {
encoding-prefixoptR raw-string
*/
export function String() {
const action = ({ globalFunction }) => {
const trimmed = globalFunction.text().trim();
const value = trimmed.slice(1, trimmed.length - 1);
return value;
const action = ({ chars }) => {
return chars.join("");
}

return (
<pattern action={action}>
<_ /><text>"</text><_ />
<SCharSequence />
<SCharSequence label="chars" />
<_ /><text>"</text><_ />
</pattern>
)
Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/generator.test.ts.snap
Expand Up @@ -164,7 +164,7 @@ exports[`ts-type TypeArrowFunctionExpression: with params 1`] = `"T extends stri
exports[`ts-type UnionType 1`] = `"(\\"0\\" | \\"1\\")"`;
exports[`ts-type UnionType: special char 1`] = `"(\\" \\" | \\"\\\\n\\" | \\"\\\\t\\")"`;
exports[`ts-type UnionType: special char 1`] = `"(\\"\\" | \\"\\\\n\\" | \\"\\\\t\\")"`;
exports[`type file TypeFile 1`] = `
"type temp = string;
Expand Down
20 changes: 20 additions & 0 deletions test/assets/ast/ImportDeclaration-3.json
@@ -0,0 +1,20 @@
{
"kind": "ImportDeclaration",
"source": "./temp",
"specifiers": [
{
"kind": "ImportSpecifier",
"imported": {
"kind": "Identifier",
"name": "Temp"
}
},
{
"kind": "ImportSpecifier",
"imported": {
"kind": "Identifier",
"name": "Temp2"
}
}
]
}
2 changes: 1 addition & 1 deletion test/assets/ast/UnionType-SpecialChar.json
Expand Up @@ -3,7 +3,7 @@
"types": [
{
"kind": "StringTypeLiteral",
"value": " "
"value": ""
},
{
"kind": "StringTypeLiteral",
Expand Down
2 changes: 1 addition & 1 deletion test/assets/ts-type/UnionType-SpecialChar
@@ -1 +1 @@
(" " | "\n" | "\t")
("" | "\n" | "\t")
2 changes: 2 additions & 0 deletions test/parser.test.tsx
Expand Up @@ -173,6 +173,8 @@ test("ImportDeclaration: 2", () => {
const parser = ReactPeg.render(<ImportDeclaration />);
const ast = parser.parse(`
import { Temp, Temp2 } from "./temp"
/* comment */
`);
saveAST(ast, "ImportDeclaration-2.json");
expect(ast).toMatchSnapshot();
Expand Down
2 changes: 1 addition & 1 deletion test/parser/__snapshots__/expression.test.tsx.snap
Expand Up @@ -70,7 +70,7 @@ Object {
"types": Array [
Object {
"kind": "StringTypeLiteral",
"value": " ",
"value": "",
},
Object {
"kind": "StringTypeLiteral",
Expand Down

0 comments on commit f30f883

Please sign in to comment.