Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 3e41b31

Browse files
committed
feat: allow custom eol characters
Closes #609
1 parent bb84cc9 commit 3e41b31

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

src/index.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as babylon from 'babylon';
22
import * as fs from 'fs';
33
import * as getStdin from 'get-stdin';
4-
54
import { generateTypings } from './deprecated';
65
import { Generator } from './generator';
76
import { createTypings } from './typings';
@@ -47,6 +46,15 @@ export interface Options {
4746
* @memberOf Options
4847
*/
4948
filename?: string;
49+
50+
/**
51+
* EOL character. This would be changed to whatever is liked to
52+
* terminate lines. Defaults to '\r\n'
53+
*
54+
* @type {string}
55+
* @memberOf Options
56+
*/
57+
eol?: string;
5058
}
5159

5260
export function cli(options: any): void {

src/typings.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import * as ASTQ from 'astq';
22
import * as dom from 'dts-dom';
3-
import pascalCase = require('pascal-case');
43
import { InstanceOfResolver, IOptions } from './index';
54
import * as types from './types';
65

6+
import pascalCase = require('pascal-case');
7+
78
export interface AstQuery {
89
ast: any;
910
query(query: string): any[];
@@ -22,6 +23,9 @@ export interface ImportedPropTypes {
2223

2324
export function createTypings(moduleName: string|null, programAst: any, options: IOptions,
2425
reactImport: string): string {
26+
// #609: configure eol character
27+
dom.config.outputEol = options.eol || '\r\n';
28+
2529
const astq = new ASTQ();
2630
const ast = {
2731
ast: programAst,

tests/parsing-test.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
// tslint:disable:no-implicit-dependencies
22
import test, { TestContext } from 'ava';
3-
43
import chalk from 'chalk';
54
import * as diff from 'diff';
65
import * as fs from 'fs';
76
import * as path from 'path';
8-
97
import * as react2dts from '../src/index';
108

119
let basedir = path.join(__dirname, '..', '..', 'tests');
@@ -118,3 +116,10 @@ test('Parsing should support an SFC with default export babeled to es6', t => {
118116
test('Parsing should suppport components that extend PureComponent', t => {
119117
compare(t, 'component', 'pure-component.jsx', 'pure-component.d.ts');
120118
});
119+
test('Parsing should suppport custom eol style', t => {
120+
textDiff(
121+
t,
122+
react2dts.generateFromFile('component', path.join(basedir, 'pure-component.jsx'), {eol: '\n'}, 'react'),
123+
fs.readFileSync(path.join(basedir, 'pure-component.d.ts')).toString().replace('\r\n', '\n')
124+
);
125+
});

0 commit comments

Comments
 (0)