This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function parserV3(code) { | |
| // interface Person { | |
| // name: string; | |
| // } | |
| const interfaceAst = { | |
| type: "InterfaceDeclaration", | |
| id: { | |
| type: "Identifier", | |
| name: "Person", | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function parserV2(code) { | |
| // fn("craig-string"); | |
| const expressionAst = { | |
| type: "ExpressionStatement", | |
| expression: { | |
| type: "CallExpression", | |
| callee: { | |
| type: "Identifier", | |
| name: "fn" | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function parser(code) { | |
| // fn("craig-string"); | |
| const expressionAst = { | |
| type: "ExpressionStatement", | |
| expression: { | |
| type: "CallExpression", | |
| callee: { | |
| type: "Identifier", | |
| name: "fn" | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface Person { | |
| name: string; | |
| } | |
| fn({ nam: "craig" }); // throw with "nam" vs "name" | |
| function fn(a: Person) {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fn("craig-string"); // throw with string vs ? | |
| function fn(a: made_up_type) {} // throw with bad type |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fn("craig-string"); // throw with string vs number | |
| function fn(a: number) {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // From our Mozilla SourceMap instance | |
| fs.writeFileSync(`./build/index.es5.js.map`, mozillaMap.toString(), "utf8"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Processor utility | |
| const generateIdentifier = id => { | |
| mappings.push( | |
| buildLocation({ | |
| name: `_identifier_ name ${id.name}`, | |
| colOffset: String(id.name).length, | |
| source: id.original.loc, | |
| node: id | |
| }) | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const buildLocation = ({ | |
| colOffset = 0, lineOffset = 0, name, source, node | |
| }) => { | |
| let endColumn, startColumn, startLine; | |
| const lastGenerated = mappings[mappings.length - 1].target; | |
| const endLine = lastGenerated.end.line + lineOffset; | |
| if (lineOffset) { | |
| endColumn = colOffset; | |
| startColumn = 0; // If new line reset column | |
| startLine = lastGenerated.end.line + lineOffset; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SourceMap instance | |
| const mozillaMap = new SourceMapGenerator({ | |
| file: "index.es5.js" | |
| }); | |
| // Local mappings instance | |
| const mappings = [ | |
| { | |
| target: { | |
| start: { line: 1, column: 0 }, |