From 2c25fd5238ff3d94c7eff2519c406a551bcfb613 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Mon, 11 Nov 2019 19:19:22 -0500 Subject: [PATCH] deconflict #-identifiers in function names (#10) --- src/print/handlers.ts | 2 +- test/samples/function-declaration/expected.js | 7 +++++++ test/samples/function-declaration/expected.js.map | 11 +++++++++++ test/samples/function-declaration/input.js | 7 +++++++ 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 test/samples/function-declaration/expected.js create mode 100644 test/samples/function-declaration/expected.js.map create mode 100644 test/samples/function-declaration/input.js diff --git a/src/print/handlers.ts b/src/print/handlers.ts index 240fc8e..fd2240a 100644 --- a/src/print/handlers.ts +++ b/src/print/handlers.ts @@ -569,7 +569,7 @@ const handlers: Record = { if (node.async) chunks.push(c('async ')); chunks.push(c(node.generator ? 'function* ' : 'function ')); - if (node.id) chunks.push(c(node.id.name, node.id)); + if (node.id) chunks.push(...handle(node.id, state)); chunks.push(c('(')); const params = node.params.map(p => handle(p, { diff --git a/test/samples/function-declaration/expected.js b/test/samples/function-declaration/expected.js new file mode 100644 index 0000000..4926fbc --- /dev/null +++ b/test/samples/function-declaration/expected.js @@ -0,0 +1,7 @@ +function foo() { + bar +} + +function foo$1() { + bar +} \ No newline at end of file diff --git a/test/samples/function-declaration/expected.js.map b/test/samples/function-declaration/expected.js.map new file mode 100644 index 0000000..d10ac20 --- /dev/null +++ b/test/samples/function-declaration/expected.js.map @@ -0,0 +1,11 @@ +{ + "version": 3, + "names": [], + "sources": [ + "input.js" + ], + "sourcesContent": [ + null + ], + "mappings": ";;;;;;" +} \ No newline at end of file diff --git a/test/samples/function-declaration/input.js b/test/samples/function-declaration/input.js new file mode 100644 index 0000000..bd96e44 --- /dev/null +++ b/test/samples/function-declaration/input.js @@ -0,0 +1,7 @@ +module.exports = ({ b }) => b` +function foo() { + bar; +} +function #foo() { + bar; +}` \ No newline at end of file