-
-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(napi/parser): introduce experimental magic string
- Loading branch information
Showing
11 changed files
with
340 additions
and
36 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,44 @@ | ||
const bindings = require('./bindings.js'); | ||
|
||
module.exports.MagicString = bindings.MagicString; | ||
module.exports.ParseResult = bindings.ParseResult; | ||
module.exports.ExportExportNameKind = bindings.ExportExportNameKind; | ||
module.exports.ExportImportNameKind = bindings.ExportImportNameKind; | ||
module.exports.ExportLocalNameKind = bindings.ExportLocalNameKind; | ||
module.exports.ImportNameKind = bindings.ImportNameKind; | ||
module.exports.parseWithoutReturn = bindings.parseWithoutReturn; | ||
module.exports.Severity = bindings.Severity; | ||
|
||
function wrap(result) { | ||
let program, module, comments, errors, magicString; | ||
return { | ||
get program() { | ||
if (!program) program = JSON.parse(result.program); | ||
return program; | ||
}, | ||
get module() { | ||
if (!module) module = result.module; | ||
return module; | ||
}, | ||
get comments() { | ||
if (!comments) comments = result.comments; | ||
return comments; | ||
}, | ||
get errors() { | ||
if (!errors) errors = result.errors; | ||
return errors; | ||
}, | ||
get magicString() { | ||
if (!magicString) magicString = result.magicString; | ||
return magicString; | ||
}, | ||
}; | ||
} | ||
|
||
module.exports.parseAsync = async function parseAsync(...args) { | ||
const result = await bindings.parseAsync(...args); | ||
result.program = JSON.parse(result.program); | ||
return result; | ||
return wrap(await bindings.parseAsync(...args)); | ||
}; | ||
|
||
module.exports.parseSync = function parseSync(...args) { | ||
const result = bindings.parseSync(...args); | ||
result.program = JSON.parse(result.program); | ||
return result; | ||
return wrap(bindings.parseSync(...args)); | ||
}; |
This file contains 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
Oops, something went wrong.