-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: @putout/engine-parser: try to use babel/generate, when recas…
…t produces broken code with additional brace (benjamn/recast#1248)
- Loading branch information
1 parent
2e35847
commit 31203ef
Showing
3 changed files
with
96 additions
and
12 deletions.
There are no files selected for viewing
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,32 +1,85 @@ | ||
'use strict'; | ||
|
||
const test = require('supertape'); | ||
const mockRequire = require('mock-require'); | ||
const { | ||
test, | ||
stub, | ||
} = require('supertape'); | ||
const montag = require('montag'); | ||
|
||
const putout = require('putout'); | ||
const { | ||
stopAll, | ||
reRequire, | ||
} = mockRequire; | ||
const { | ||
parse, | ||
print, | ||
} = putout; | ||
|
||
test('putout: parser: print: long lines', (t) => { | ||
const source = montag` | ||
test.only('putout: parseOptions: code mods directory: .putout: exclude node_modules', (t) => { | ||
const empty = {}; | ||
}); | ||
`; | ||
|
||
const expected = montag` | ||
import {test} from 'supertape'; | ||
test('putout: parseOptions: code mods directory: .putout: exclude node_modules', (t) => { | ||
const empty = {}; | ||
t.end(); | ||
}); | ||
`; | ||
|
||
const {code} = putout(source, { | ||
plugins: [ | ||
'tape', | ||
], | ||
plugins: ['tape'], | ||
}); | ||
|
||
t.equal(code, expected); | ||
t.end(); | ||
}); | ||
|
||
test('putout: parser: print: bad recast output', (t) => { | ||
const source = montag` | ||
export default () => { | ||
return ( | ||
<h1>hello</h1> | ||
); | ||
} | ||
`; | ||
const invalid = montag` | ||
export default () => { | ||
return ( | ||
<h1>hello</h1>) | ||
); | ||
} | ||
`; | ||
const expected = montag` | ||
export default (() => { | ||
return <h1>hello</h1>; | ||
}); | ||
`; | ||
const recastPrint = stub().returns({ | ||
code: invalid, | ||
}); | ||
|
||
mockRequire('@putout/recast', { | ||
print: recastPrint, | ||
}); | ||
const print = reRequire('./print'); | ||
const ast = parse(source); | ||
const result = print(ast); | ||
|
||
stopAll(); | ||
|
||
t.equal(result, expected); | ||
t.end(); | ||
}); | ||
|
||
test('putout: parser: print: empty', (t) => { | ||
const source = ''; | ||
const ast = parse(source); | ||
const result = print(ast); | ||
const expected = ''; | ||
|
||
t.equal(result, expected); | ||
t.end(); | ||
}); |
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