Skip to content

Commit

Permalink
fix: handle undefined exports (#24)
Browse files Browse the repository at this point in the history
* handle undefined exports

* add test to handle undefined exports
  • Loading branch information
Kent C. Dodds authored Jul 19, 2017
2 parents 4d5ba72 + e123d02 commit 34779bd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/__tests__/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,16 @@ module.exports = fib(10)
module.exports = 55;
`;
exports[`34. preval 1`] = `
// @preval
let smth = {}
module.exports = smth.UNDEFINED;
↓ ↓ ↓ ↓ ↓ ↓
// this file was prevaled
module.exports = undefined;
`;
7 changes: 7 additions & 0 deletions src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ pluginTester({
import x from "./fixtures/compute-one.js";
`,
},
{
code: `
// @preval
let smth = {}
module.exports = smth.UNDEFINED;
`,
},

// please add a file for your use-case
// in the `fixtures` directory and make
Expand Down
6 changes: 5 additions & 1 deletion src/object-to-ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ function objectToAST(object) {
}

function stringify(object) {
return JSON.stringify(object, stringifyReplacer).replace(
let str = JSON.stringify(object, stringifyReplacer)
if (str === undefined) {
str = 'undefined'
}
return str.replace(
/"__FUNCTION_START__(.*?)__FUNCTION_END__"/g,
functionReplacer,
)
Expand Down

0 comments on commit 34779bd

Please sign in to comment.