(parserId: string)
| 47 | }); |
| 48 | |
| 49 | function runTestsForParser(parserId: string) { |
| 50 | const parserName = parserId.split("/").pop(); |
| 51 | |
| 52 | if ( |
| 53 | nodeMajorVersion < 6 && |
| 54 | (parserName === "babel" || |
| 55 | parserName === "flow" || |
| 56 | parserName === "typescript") |
| 57 | ) { |
| 58 | // Babel 7 no longer supports Node 4 or 5. |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | if (!parserName) { |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | const parser = require(parserId); |
| 67 | |
| 68 | it("[" + parserName + "] empty source", function () { |
| 69 | const printer = new Printer(); |
| 70 | |
| 71 | function check(code: string) { |
| 72 | const ast = parse(code, { parser }); |
| 73 | assert.strictEqual(printer.print(ast).code, code); |
| 74 | } |
| 75 | |
| 76 | check(""); |
| 77 | check("/* block comment */"); |
| 78 | check("// line comment"); |
| 79 | check("\t\t\t"); |
| 80 | check(eol); |
| 81 | check(eol + eol); |
| 82 | check(" "); |
| 83 | }); |
| 84 | |
| 85 | const lineCommentTypes: { [name: string]: string } = { |
| 86 | acorn: "Line", |
| 87 | babel: "CommentLine", |
| 88 | esprima: "Line", |
| 89 | flow: "CommentLine", |
| 90 | typescript: "CommentLine", |
| 91 | }; |
| 92 | |
| 93 | it("[" + parserName + "] parser basics", function testParser(done) { |
| 94 | const code = testParser + ""; |
| 95 | const ast = parse(code, { parser }); |
| 96 | |
| 97 | namedTypes.File.assert(ast); |
| 98 | assert.ok(getReprinter(FastPath.from(ast))); |
| 99 | |
| 100 | const funDecl = ast.program.body[0]; |
| 101 | const funBody = funDecl.body; |
| 102 | |
| 103 | namedTypes.FunctionDeclaration.assert(funDecl); |
| 104 | namedTypes.BlockStatement.assert(funBody); |
| 105 | assert.ok(getReprinter(FastPath.from(funBody))); |
| 106 |
nothing calls this directly
no test coverage detected
searching dependent graphs…