react-docgen-typescript
Advanced tools
Comparing version
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var chai_1 = require("chai"); | ||
var fs = require("fs"); | ||
var path = require("path"); | ||
var ts = require("typescript"); | ||
var parser_1 = require("../parser"); | ||
@@ -572,3 +574,28 @@ var testUtils_1 = require("./testUtils"); | ||
}); | ||
describe('parseWithProgramProvider', function () { | ||
it('should accept existing ts.Program instance', function () { | ||
var programProviderInvoked = false; | ||
// mimic a third party library providing a ts.Program instance. | ||
var programProvider = function () { | ||
// need to navigate to root because tests run on compiled tests | ||
// and tsc does not include json files | ||
var tsconfigPath = path.join(__dirname, '../../src/__tests__/data/tsconfig.json'); | ||
var basePath = path.dirname(tsconfigPath); | ||
var _a = ts.readConfigFile(tsconfigPath, function (filename) { | ||
return fs.readFileSync(filename, 'utf8'); | ||
}), config = _a.config, error = _a.error; | ||
chai_1.assert.isUndefined(error); | ||
var _b = ts.parseJsonConfigFileContent(config, ts.sys, basePath, {}, tsconfigPath), options = _b.options, errors = _b.errors; | ||
chai_1.assert.lengthOf(errors, 0); | ||
programProviderInvoked = true; | ||
return ts.createProgram([testUtils_1.fixturePath('Column')], options); | ||
}; | ||
var result = parser_1.withDefaultConfig().parse([testUtils_1.fixturePath('Column')], programProvider); | ||
testUtils_1.checkComponent(result, { | ||
Column: {} | ||
}, false); | ||
chai_1.assert.isTrue(programProviderInvoked); | ||
}); | ||
}); | ||
}); | ||
//# sourceMappingURL=parser.js.map |
@@ -41,3 +41,3 @@ import * as ts from 'typescript'; | ||
export interface FileParser { | ||
parse(filePathOrPaths: string | string[]): ComponentDoc[]; | ||
parse(filePathOrPaths: string | string[], programProvider?: () => ts.Program): ComponentDoc[]; | ||
} | ||
@@ -44,0 +44,0 @@ /** |
@@ -54,7 +54,9 @@ "use strict"; | ||
return { | ||
parse: function (filePathOrPaths) { | ||
parse: function (filePathOrPaths, programProvider) { | ||
var filePaths = Array.isArray(filePathOrPaths) | ||
? filePathOrPaths | ||
: [filePathOrPaths]; | ||
var program = ts.createProgram(filePaths, compilerOptions); | ||
var program = programProvider | ||
? programProvider() | ||
: ts.createProgram(filePaths, compilerOptions); | ||
var parser = new Parser(program, parserOpts); | ||
@@ -61,0 +63,0 @@ var checker = program.getTypeChecker(); |
{ | ||
"name": "react-docgen-typescript", | ||
"version": "1.7.0", | ||
"version": "1.8.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -173,4 +173,6 @@ # react-docgen-typescript | ||
**@strothj** *Jason Strothmann* | ||
## Thanks to others | ||
The integration with React Styleguidist wouldn't be possible without [Vyacheslav Slinko](https://github.com/vslinko) pull request [#118](https://github.com/styleguidist/react-styleguidist/pull/118) at React Styleguidist. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
115703
2.32%1507
1.96%178
1.14%3
50%