Merge pull request #4120 from basarat/feat/shebang

Shebang
This commit is contained in:
Mohamed Hegazy
2015-08-04 10:00:38 -07:00
11 changed files with 116 additions and 11 deletions

View File

@@ -75,28 +75,28 @@ function delint(sourceFile) {
delintNode(sourceFile);
function delintNode(node) {
switch (node.kind) {
case 196 /* ForStatement */:
case 197 /* ForInStatement */:
case 195 /* WhileStatement */:
case 194 /* DoStatement */:
if (node.statement.kind !== 189 /* Block */) {
case 197 /* ForStatement */:
case 198 /* ForInStatement */:
case 196 /* WhileStatement */:
case 195 /* DoStatement */:
if (node.statement.kind !== 190 /* Block */) {
report(node, "A looping statement's contents should be wrapped in a block body.");
}
break;
case 193 /* IfStatement */:
case 194 /* IfStatement */:
var ifStatement = node;
if (ifStatement.thenStatement.kind !== 189 /* Block */) {
if (ifStatement.thenStatement.kind !== 190 /* Block */) {
report(ifStatement.thenStatement, "An if statement's contents should be wrapped in a block body.");
}
if (ifStatement.elseStatement &&
ifStatement.elseStatement.kind !== 189 /* Block */ &&
ifStatement.elseStatement.kind !== 193 /* IfStatement */) {
ifStatement.elseStatement.kind !== 190 /* Block */ &&
ifStatement.elseStatement.kind !== 194 /* IfStatement */) {
report(ifStatement.elseStatement, "An else statement's contents should be wrapped in a block body.");
}
break;
case 178 /* BinaryExpression */:
case 179 /* BinaryExpression */:
var op = node.operatorToken.kind;
if (op === 29 /* EqualsEqualsToken */ || op == 30 /* ExclamationEqualsToken */) {
if (op === 30 /* EqualsEqualsToken */ || op == 31 /* ExclamationEqualsToken */) {
report(node, "Use '===' and '!=='.");
}
break;

View File

@@ -0,0 +1,8 @@
//// [shebang.ts]
#!/usr/bin/env node
var foo = 'I wish the generated JS to be executed in node';
//// [shebang.js]
#!/usr/bin/env node
var foo = 'I wish the generated JS to be executed in node';

View File

@@ -0,0 +1,5 @@
=== tests/cases/compiler/shebang.ts ===
#!/usr/bin/env node
var foo = 'I wish the generated JS to be executed in node';
>foo : Symbol(foo, Decl(shebang.ts, 1, 3))

View File

@@ -0,0 +1,6 @@
=== tests/cases/compiler/shebang.ts ===
#!/usr/bin/env node
var foo = 'I wish the generated JS to be executed in node';
>foo : string
>'I wish the generated JS to be executed in node' : string

View File

@@ -0,0 +1,20 @@
tests/cases/compiler/shebangError.ts(2,1): error TS1127: Invalid character.
tests/cases/compiler/shebangError.ts(2,2): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
tests/cases/compiler/shebangError.ts(2,12): error TS2304: Cannot find name 'env'.
tests/cases/compiler/shebangError.ts(2,16): error TS1005: ';' expected.
tests/cases/compiler/shebangError.ts(2,16): error TS2304: Cannot find name 'node'.
==== tests/cases/compiler/shebangError.ts (5 errors) ====
var foo = 'Shebang is only allowed on the first line';
#!/usr/bin/env node
!!! error TS1127: Invalid character.
~~~~~~~~~
!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
~~~
!!! error TS2304: Cannot find name 'env'.
~~~~
!!! error TS1005: ';' expected.
~~~~
!!! error TS2304: Cannot find name 'node'.

View File

@@ -0,0 +1,8 @@
//// [shebangError.ts]
var foo = 'Shebang is only allowed on the first line';
#!/usr/bin/env node
//// [shebangError.js]
var foo = 'Shebang is only allowed on the first line';
!/usr/bin / env;
node;

View File

@@ -0,0 +1,2 @@
#!/usr/bin/env node
var foo = 'I wish the generated JS to be executed in node';

View File

@@ -0,0 +1,2 @@
var foo = 'Shebang is only allowed on the first line';
#!/usr/bin/env node