Skip to content

Commit

Permalink
feat(tsfmt): support typescript@1.5.0-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
vvakame committed May 5, 2015
1 parent a621319 commit a5f7f19
Show file tree
Hide file tree
Showing 8 changed files with 773 additions and 504 deletions.
13 changes: 5 additions & 8 deletions dtsm.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,16 @@
"bundle": "typings/bundle.d.ts",
"dependencies": {
"node/node.d.ts": {
"ref": "32f0a90dab26f70b206407ac24d4d622d0f0f408"
},
"typescript/typescript.d.ts": {
"ref": "32f0a90dab26f70b206407ac24d4d622d0f0f408"
"ref": "575d70adcad0086ec8c6f672a5eb569a4689486c"
},
"es6-promise/es6-promise.d.ts": {
"ref": "32f0a90dab26f70b206407ac24d4d622d0f0f408"
"ref": "575d70adcad0086ec8c6f672a5eb569a4689486c"
},
"mocha/mocha.d.ts": {
"ref": "32f0a90dab26f70b206407ac24d4d622d0f0f408"
"ref": "575d70adcad0086ec8c6f672a5eb569a4689486c"
},
"power-assert/power-assert.d.ts": {
"ref": "32f0a90dab26f70b206407ac24d4d622d0f0f408"
"ref": "575d70adcad0086ec8c6f672a5eb569a4689486c"
}
}
}
}
22 changes: 17 additions & 5 deletions lib/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import utils = require("./utils");

// from https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#pretty-printer-using-the-ls-formatter

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

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

// Get the formatting edits on the input sources
Expand All @@ -33,8 +33,20 @@ function format(text:string, options = utils.createDefaultFormatCodeOptions()) {
var result = text;
for (var i = edits.length - 1; i >= 0; i--) {
var change = edits[i];
var head = result.slice(0, change.span.start());
var tail = result.slice(change.span.start() + change.span.length());
var head: string;
if (typeof change.span.start === "number") {
head = result.slice(0, change.span.start);
} else {
// backward compat for typescript-1.4.1
head = result.slice(0, (<any>change.span.start)());
}
var tail: string;
if (typeof change.span.start === "number") {
tail = result.slice(change.span.start + change.span.length);
} else {
// backward compat for typescript-1.4.1
tail = result.slice((<any>change.span.start)() + (<any>change.span.length)());
}
result = head + change.newText + tail;
}
return result;
Expand Down
2 changes: 1 addition & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// <reference path="../typings/node/node.d.ts" />
/// <reference path="../typings/typescript/typescript.d.ts" />
/// <reference path="../node_modules/typescript/bin/typescript.d.ts" />

"use strict";

Expand Down
1,167 changes: 690 additions & 477 deletions npm-shrinkwrap.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@
"dependencies": {
"commandpost": "0.1.1",
"editorconfig": "0.12.2",
"es6-promise": "2.0.1",
"typescript": "1.4.1"
"es6-promise": "2.1.1",
"typescript": "1.5.0-beta"
},
"devDependencies": {
"espower-loader": "0.10.0",
"grunt": "0.4.5",
"grunt-contrib-clean": "0.6.0",
"grunt-conventional-changelog": "^1.1.0",
"grunt-conventional-changelog": "1.2.2",
"grunt-dts-bundle": "0.2.0",
"grunt-dtsm": "0.2.7",
"grunt-dtsm": "0.2.8",
"grunt-exec": "0.4.6",
"grunt-mocha-test": "0.12.7",
"grunt-ts": "3.0.0",
"grunt-ts": "4.0.1",
"grunt-tslint": "2.0.0",
"load-grunt-tasks": "3.1.0",
"power-assert": "0.10.2"
"power-assert": "0.11.0"
}
}
12 changes: 6 additions & 6 deletions test/expected/tsfmt/b/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Vector/*
static norm( v: Vector )/*
*/ {
var mag=Vector.mag( v );
var div=( mag===0 )?Infinity:1.0/mag;
var div=( mag===0 )? Infinity:1.0/mag;
return Vector.times( div,v );
}

Expand Down Expand Up @@ -72,7 +72,7 @@ class Color/*

static toDrawingColor( c: Color )/*
*/ {
var legalize=d => d>1?1:d;
var legalize=d => d>1? 1:d;
return {
r: Math.floor( legalize( c.r )*255 ),
g: Math.floor( legalize( c.g )*255 ),
Expand Down Expand Up @@ -295,7 +295,7 @@ class RayTracer/*
var reflectDir=Vector.minus( d,Vector.times( 2,Vector.times( Vector.dot( normal,d ),normal ) ) );
var naturalColor=Color.plus( Color.background,
this.getNaturalColor( isect.thing,pos,normal,reflectDir,scene ) );
var reflectedColor=( depth>=this.maxDepth )?Color.grey:this.getReflectionColor( isect.thing,pos,normal,reflectDir,scene,depth );
var reflectedColor=( depth>=this.maxDepth )? Color.grey:this.getReflectionColor( isect.thing,pos,normal,reflectDir,scene,depth );
return Color.plus( naturalColor,reflectedColor );
}

Expand All @@ -311,17 +311,17 @@ class RayTracer/*
var ldis=Vector.minus( light.pos,pos );
var livec=Vector.norm( ldis );
var neatIsect=this.testRay( { start: pos,dir: livec },scene );
var isInShadow=( neatIsect===undefined )?false:( neatIsect<=Vector.mag( ldis ) );
var isInShadow=( neatIsect===undefined )? false:( neatIsect<=Vector.mag( ldis ) );
if( isInShadow )/*
*/ {
return col;
} else/*
*/ {
var illum=Vector.dot( livec,norm );
var lcolor=( illum>0 )?Color.scale( illum,light.color )
var lcolor=( illum>0 )? Color.scale( illum,light.color )
:Color.defaultColor;
var specular=Vector.dot( livec,Vector.norm( rd ) );
var scolor=( specular>0 )?Color.scale( Math.pow( specular,thing.surface.roughness ),light.color )
var scolor=( specular>0 )? Color.scale( Math.pow( specular,thing.surface.roughness ),light.color )
:Color.defaultColor;
return Color.plus( col,Color.plus( Color.times( thing.surface.diffuse( pos ),lcolor ),
Color.times( thing.surface.specular( pos ),scolor ) ) );
Expand Down
47 changes: 47 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"version": "1.5.0-alpha",
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"declaration": false,
"noImplicitAny": false,
"removeComments": true,
"noLib": false
},
"filesGlob": [
"./**/*.ts",
"!./node_modules/**/*.ts",
"./node_modules/typescript/bin/typescript.d.ts",
"!./example/**/*.ts",
"!./test/fixture/**/*.ts",
"!./test/expected/**/*.ts",
"!./*.d.ts"
],
"files": [
"./lib/cli.d.ts",
"./lib/cli.ts",
"./lib/editorconfig.d.ts",
"./lib/formatter.d.ts",
"./lib/formatter.ts",
"./lib/index.d.ts",
"./lib/index.ts",
"./lib/provider/base.d.ts",
"./lib/provider/base.ts",
"./lib/provider/editorconfig.d.ts",
"./lib/provider/editorconfig.ts",
"./lib/provider/tslintjson.d.ts",
"./lib/provider/tslintjson.ts",
"./lib/utils.d.ts",
"./lib/utils.ts",
"./test/indexSpec.d.ts",
"./test/indexSpec.ts",
"./typings/bundle.d.ts",
"./typings/empower/empower.d.ts",
"./typings/es6-promise/es6-promise.d.ts",
"./typings/mocha/mocha.d.ts",
"./typings/node/node.d.ts",
"./typings/power-assert-formatter/power-assert-formatter.d.ts",
"./typings/power-assert/power-assert.d.ts",
"./node_modules/typescript/bin/typescript.d.ts"
]
}
2 changes: 1 addition & 1 deletion typescript-formatter.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Generated by dts-bundle v0.2.0
// Dependencies for this module:
// typings/typescript/typescript.d.ts
// node_modules/typescript/bin/typescript.d.ts

declare module 'typescript-formatter' {
import ts = require("typescript");
Expand Down

0 comments on commit a5f7f19

Please sign in to comment.