Skip to content

Commit 77e2ff1

Browse files
author
Kent C. Dodds
committed
fix(comments): preserveComments
1 parent 378c966 commit 77e2ff1

3 files changed

Lines changed: 64 additions & 0 deletions

File tree

src/__tests__/__snapshots__/index.js.snap

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,47 @@ Error: <PROJECT_ROOT>/src/__tests__/index.js: codegen: Must module.exports a str
8888
8989
`;
9090
91+
exports[`5. includes code comments 1`] = `
92+
93+
codegen\`
94+
module.exports = \\\`
95+
// before
96+
var x = 'hi'
97+
/*
98+
* after
99+
*/
100+
101+
// call foo
102+
console.log(foo())
103+
104+
/**
105+
* jsdoc
106+
* @return {string} cool I guess
107+
*/
108+
function foo() {
109+
return 'foo'
110+
}
111+
\\\`
112+
\`
113+
114+
↓ ↓ ↓ ↓ ↓ ↓
115+
116+
// before
117+
var x = 'hi'; /*
118+
* after
119+
*/ // call foo
120+
121+
console.log(foo()); /**
122+
* jsdoc
123+
* @return {string} cool I guess
124+
*/
125+
126+
function foo() {
127+
return 'foo';
128+
}
129+
130+
`;
131+
91132
exports[`6. codegen 1`] = `
92133
93134
// @codegen

src/__tests__/index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,27 @@ pluginTester({
111111
'handles multipe nodes': `
112112
codegen.require('./fixtures/multiple-nodes')
113113
`,
114+
'includes code comments': `
115+
codegen\`
116+
module.exports = \\\`
117+
// before
118+
var x = 'hi'
119+
/*
120+
* after
121+
*/
122+
123+
// call foo
124+
console.log(foo())
125+
126+
/**
127+
* jsdoc
128+
* @return {string} cool I guess
129+
*/
130+
function foo() {
131+
return 'foo'
132+
}
133+
\\\`
134+
\`
135+
`,
114136
},
115137
})

src/get-replacement.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ function stringToAST(string) {
2020
}
2121
return template(string, {
2222
sourceType: 'module',
23+
preserveComments: true,
2324
plugins: [
2425
// add more on request...
2526
'jsx',

0 commit comments

Comments
 (0)