Skip to content

Commit b9196e9

Browse files
committed
feat(tsfmt): pass specified file name to typescript language service. support tsx files.
1 parent e15ae14 commit b9196e9

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

lib/formatter.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import utils = require("./utils");
77

88
// Note: this uses ts.formatting which is part of the typescript 1.4 package but is not currently
99
// exposed in the public typescript.d.ts. The typings should be exposed in the next release.
10-
function format(text: string, options = utils.createDefaultFormatCodeOptions()) {
10+
function format(fileName: string, text: string, options = utils.createDefaultFormatCodeOptions()) {
1111
"use strict";
1212

1313
// Parse the source text
14-
var sourceFile = ts.createSourceFile("file.ts", text, ts.ScriptTarget.Latest, (<any>/* backward compat for typescript-1.4.1 */"0"));
14+
var sourceFile = ts.createSourceFile(fileName, text, ts.ScriptTarget.Latest, (<any>/* backward compat for typescript-1.4.1 */"0"));
1515
fixupParentReferences(sourceFile);
1616

1717
// Get the formatting edits on the input sources

lib/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export function processString(fileName: string, content: string, opts: Options):
101101
return Promise
102102
.all(optGenPromises)
103103
.then(() => {
104-
var formattedCode = formatter(content, options);
104+
var formattedCode = formatter(fileName, content, options);
105105
if ((<any>formattedCode).trimRight) {
106106
formattedCode = (<any>formattedCode).trimRight();
107107
formattedCode += "\n";

0 commit comments

Comments
 (0)