file_path stringlengths 3 280 | file_language stringclasses 66 values | content stringlengths 1 1.04M | repo_name stringlengths 5 92 | repo_stars int64 0 154k | repo_description stringlengths 0 402 | repo_primary_language stringclasses 108 values | developer_username stringlengths 1 25 | developer_name stringlengths 0 30 | developer_company stringlengths 0 82 |
|---|---|---|---|---|---|---|---|---|---|
crates/swc_ecma_parser/tests/tsc/parserSymbolIndexer3.ts | TypeScript | //@target: ES6
class C {
static [s: symbol]: string;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserSymbolIndexer4.ts | TypeScript | //@target: ES6
var x: {
[s: symbol]: string;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserSymbolProperty1.ts | TypeScript | //@target: ES6
interface I {
[Symbol.iterator]: string;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserSymbolProperty2.ts | TypeScript | //@target: ES6
interface I {
[Symbol.unscopables](): string;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserSymbolProperty3.ts | TypeScript | //@target: ES6
declare class C {
[Symbol.unscopables](): string;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserSymbolProperty4.ts | TypeScript | //@target: ES6
declare class C {
[Symbol.toPrimitive]: string;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserSymbolProperty5.ts | TypeScript | //@target: ES6
class C {
[Symbol.toPrimitive]: string;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserSymbolProperty6.ts | TypeScript | //@target: ES6
class C {
[Symbol.toStringTag]: string = "";
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserSymbolProperty7.ts | TypeScript | //@target: ES6
class C {
[Symbol.toStringTag](): void { }
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserSymbolProperty8.ts | TypeScript | //@target: ES6
var x: {
[Symbol.toPrimitive](): string
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserSymbolProperty9.ts | TypeScript | //@target: ES6
var x: {
[Symbol.toPrimitive]: string
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserSyntaxWalker.generated.ts | TypeScript | //declare module "fs" {
// export class File {
// constructor(filename: string);
// public ReadAllText(): string;
// }
// export interface IFile {
// [index: number]: string;
// }
//}
//import fs = module("fs");
//module TypeScriptAllInOne {
// export class Program {
// static Main(...args: string[]) {
// try {
// var bfs = new BasicFeatures();
// var retValue: number = 0;
// retValue = bfs.VARIABLES();
// if (retValue != 0) {
// return 1;
// }
// retValue = bfs.STATEMENTS(4);
// if (retValue != 0) {
// return 1;
// }
// retValue = bfs.TYPES();
// if (retValue != 0) {
// return 1;
// }
// retValue = bfs.OPERATOR();
// if (retValue != 0) {
// return 1;
// }
// }
// catch (e) {
// console.log(e);
// }
// finally {
// }
// console.log('Done');
// return 0;
// }
// }
// class BasicFeatures {
// /// <summary>
// /// Test various of variables. Including nullable,key world as variable,special format
// /// </summary>
// /// <returns></returns>
// public VARIABLES(): number {
// var local = Number.MAX_VALUE;
// var min = Number.MIN_VALUE;
// var inf = Number.NEGATIVE_INFINITY;
// var nan = Number.NaN;
// var undef = undefined;
// var п = local;
// var м = local;
// var local5 = <fs.File>null;
// var local6 = local5 instanceof fs.File;
// var hex = 0xBADC0DE, Hex = 0XDEADBEEF;
// var float = 6.02e23, float2 = 6.02E-23
// var char = 'c', \u0066 = '\u0066', hexchar = '\x42';
// var quoted = '"', quoted2 = "'";
// var reg = /\w*/;
// var objLit = { "var": number = 42, equals: function (x) { return x["var"] === 42; }, toString: () => 'objLit{42}' };
// var weekday = Weekdays.Monday;
// var con = char + f + hexchar + float.toString() + float2.toString() + reg.toString() + objLit + weekday;
// //
// var any = 0;
// var boolean = 0;
// var declare = 0;
// var constructor = 0;
// var get = 0;
// var implements = 0;
// var interface = 0;
// var let = 0;
// var module = 0;
// var number = 0;
// var package = 0;
// var private = 0;
// var protected = 0;
// var public = 0;
// var set = 0;
// var static = 0;
// var string = 0;
// var yield = 0;
// var sum3 = any + boolean + declare + constructor + get + implements + interface + let + module + number + package + private + protected + public + set + static + string + yield;
// return 0;
// }
// /// <summary>
// /// Test different statements. Including if-else,swith,foreach,(un)checked,lock,using,try-catch-finally
// /// </summary>
// /// <param name="i"></param>
// /// <returns></returns>
// STATEMENTS(i: number): number {
// var retVal = 0;
// if (i == 1)
// retVal = 1;
// else
// retVal = 0;
// switch (i) {
// case 2:
// retVal = 1;
// break;
// case 3:
// retVal = 1;
// break;
// default:
// break;
// }
// for (var x in { x: 0, y: 1 }) {
// }
// try {
// throw null;
// }
// catch (Exception) {
// }
// finally {
// try { }
// catch (Exception) { }
// }
// return retVal;
// }
// /// <summary>
// /// Test types in ts language. Including class,struct,interface,delegate,anonymous type
// /// </summary>
// /// <returns></returns>
// public TYPES(): number {
// var retVal = 0;
// var c = new CLASS();
// var xx: IF = c;
// retVal += c.Property;
// retVal += c.Member();
// retVal += xx ^= Foo() ? 0 : 1;
// //anonymous type
// var anony = { a: new CLASS() };
// retVal += anony.a.d();
// return retVal;
// }
// ///// <summary>
// ///// Test different operators
// ///// </summary>
// ///// <returns></returns>
// public OPERATOR(): number {
// var a: number[] = [1, 2, 3, 4, implements , ];/*[] bug*/ // YES []
// var i = a[1];/*[]*/
// i = i + i - i * i / i % i & i | i ^ i;/*+ - * / % & | ^*/
// var b = true && false || true ^ false;/*& | ^*/
// b = !b;/*!*/
// i = ~i;/*~i*/
// b = i < (i - continue ) && (i + 1) > i;/*< && >*/
// var f = true ? 1 : 0;/*? :*/ // YES :
// i++;/*++*/
// i--;/*--*/
// b = true && false || true;/*&& ||*/
// i = i << 5;/*<<*/
// i = i >> 5;/*>>*/
// var j = i;
// b = i == j && i != j && i <= j && i >= j;/*= == && != <= >=*/
// i += <number>5.0;/*+=*/
// i -= i;/*-=*/
// i *= i;/**=*/
// if (i == 0)
// i++;
// i /= i;/*/=*/
// i %= i;/*%=*/
// i &= i;/*&=*/
// i |= i;/*|=*/
// i ^= i;/*^=*/
// i <<= i;/*<<=*/
// i >>= i;/*>>=*/
// if (i == 0 && !b && f == 1)
// return 0;
// else return 1;
// }
// }
// interface IF {
// Foo <!-- ): boolean;
// }
// class CLASS implements IF {
// public d = () => ' return 0; };
// public get Property() { return 0; }
// public Member() {
// return 0;
// }
// public Foo(): boolean {
// var myEvent = () => { return 1; };
// if (myEvent() == 1)
// return true;
// else
// return false;
// }
// }
// // todo: use these
// class A {
// public method1(val:number) {
// return val;
// }
// public method2() {
// return 2 * this.method1(2);
// }
// }
// class B extends A {
// public method2() {
// return this.method1(2);
// }
// }
// class Overloading {
// private otherValue = 42;
// constructor(private value: number, public name: string) { }
// public Overloads(value: string);
// public Overloads(value: string, ...rest: string[]) { }
// public DefaultValue(value?: string = "Hello") { }
// }
//}
//enum Weekdays {
// Monday,
// Tuesday,
// Weekend,
//}
//enum Fruit {
// Apple,
// Pear
//}
//interface IDisposable {
// Dispose(): void;
//}
//TypeScriptAllInOne.Program.Main();
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserTernaryAndCommaOperators1.ts | TypeScript | b.src ? 1 : 2, c && d;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserTypeQuery1.ts | TypeScript | var v: typeof A | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserTypeQuery2.ts | TypeScript | var v: typeof A; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserTypeQuery5.ts | TypeScript | var v: typeof A.B | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserTypeQuery6.ts | TypeScript | var v: typeof A.B; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserTypeQuery7.ts | TypeScript | var v: typeof A[] | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserTypeQuery8.ts | TypeScript | var v: typeof A<B> | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserTypeQuery9.ts | TypeScript | var s: typeof A[];
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserUnaryExpression1.ts | TypeScript | ++this; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserUnaryExpression2.ts | TypeScript | ++function(e) { } | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserUnaryExpression3.ts | TypeScript | ++[0]; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserUnaryExpression4.ts | TypeScript | ++{}; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserUnaryExpression7.ts | TypeScript | ++ new Foo(); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserUnicode1.ts | TypeScript | try {
var \u0078x = 6;
if (xx !== 6) {
$ERROR('#6.1: var \\u0078x = 1; xx === 6. Actual: ' + (xx));
}
}
catch (e) {
$ERROR('#6.2: var \\u0078x = 1; xx === 6. Actual: ' + (xx));
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserUnicode2.ts | TypeScript | var 才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüß才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüßAbcd123 = 1; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserUnicode3.ts | TypeScript | class 剩下 {
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserUnicodeWhitespaceCharacter1.ts | TypeScript | function foo(){ }
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserUsingConstructorAsIdentifier.ts | TypeScript | function define(constructor, instanceMembers, staticMembers) {
constructor = constructor || function () { };
PluginUtilities.Utilities.markSupportedForProcessing(constructor);
if (instanceMembers) {
initializeProperties(constructor.prototype, instanceMembers);
}
if (staticMembers) {
initializeProperties(constructor, staticMembers);
}
return constructor;
}
function derive(baseClass, constructor, instanceMembers, staticMembers) {
if (baseClass) {
constructor = constructor || function () { };
var basePrototype = baseClass.prototype;
constructor.prototype = Object.create(basePrototype);
PluginUtilities.Utilities.markSupportedForProcessing(constructor);
Object.defineProperty(constructor.prototype, "constructor", { value: constructor, writable: true, configurable: true, enumerable: true });
if (instanceMembers) {
initializeProperties(constructor.prototype, instanceMembers);
}
if (staticMembers) {
initializeProperties(constructor, staticMembers);
}
return constructor;
} else {
return define(constructor, instanceMembers, staticMembers);
}
}
function mix(constructor) {
constructor = constructor || function () { };
var i, len;
for (i = 1, len = arguments.length; i < len; i++) {
initializeProperties(constructor.prototype, arguments[i]);
}
return constructor;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserVariableDeclaration1.ts | TypeScript |
var selection = a,
position = b,
model = c,
support = d; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserVariableDeclaration11.ts | TypeScript | var a,b; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserVariableDeclaration2.ts | TypeScript | (function() {
var check = function () {
}
var checkNot = function () {
}
MUnit.test(a);
})(); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserVariableDeclaration3.ts | TypeScript | function runTests() {
var outfile = new Harness.Compiler.WriterAggregator()
, outerr = new Harness.Compiler.WriterAggregator()
, compiler = <TypeScript.TypeScriptCompiler>new TypeScript.TypeScriptCompiler(outerr)
, code;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserVariableDeclaration4.d.ts | TypeScript | declare var v; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserVariableDeclaration7.ts | TypeScript | var a,b | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserVariableDeclaration9.ts | TypeScript | var a; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserVariableStatement1.ts | TypeScript | var a,
b,
c | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserVariableStatement2.ts | TypeScript | var a
, b
, c | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserVariableStatement3.ts | TypeScript | var
a,
b,
c | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserVariableStatement4.ts | TypeScript | var
a
, b
, c | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserVoidExpression1.ts | TypeScript | void 0; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserWithStatement2.ts | TypeScript | with (1)
return; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserX_ArrowFunction4.ts | TypeScript | var v = (a, b) => {
}; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parser_breakInIterationOrSwitchStatement1.ts | TypeScript | while (true) {
break;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parser_breakInIterationOrSwitchStatement2.ts | TypeScript | do {
break;
}
while (true); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parser_breakInIterationOrSwitchStatement3.ts | TypeScript | for (;;) {
break;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parser_breakInIterationOrSwitchStatement4.ts | TypeScript | for (var i in something) {
break;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parser_breakTarget1.ts | TypeScript | target:
break target; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parser_breakTarget2.ts | TypeScript | target:
while (true) {
break target;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parser_breakTarget3.ts | TypeScript | // @allowUnusedLabels: true
target1:
target2:
while (true) {
break target1;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parser_breakTarget4.ts | TypeScript | // @allowUnusedLabels: true
target1:
target2:
while (true) {
break target2;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parser_continueInIterationStatement1.ts | TypeScript | while (true) {
continue;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parser_continueInIterationStatement2.ts | TypeScript | do {
continue;
}
while (true); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parser_continueInIterationStatement3.ts | TypeScript | for (;;) {
continue;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parser_continueInIterationStatement4.ts | TypeScript | for (var i in something) {
continue;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parser_continueLabel.ts | TypeScript | label1: for(var i = 0; i < 1; i++) {
continue label1;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parser_continueTarget2.ts | TypeScript | target:
while (true) {
continue target;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parser_continueTarget3.ts | TypeScript | // @allowUnusedLabels: true
target1:
target2:
while (true) {
continue target1;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parser_continueTarget4.ts | TypeScript | // @allowUnusedLabels: true
target1:
target2:
while (true) {
continue target2;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parser_duplicateLabel3.ts | TypeScript | // @allowUnusedLabels: true
target:
while (true) {
function f() {
target:
while (true) {
}
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parser_duplicateLabel4.ts | TypeScript | // @allowUnusedLabels: true
// @allowUnreachableCode: true
target:
while (true) {
}
target:
while (true) {
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parserindenter.ts | TypeScript | //
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
///<reference path='formatting.ts' />
module Formatting {
export class Indenter implements ILineIndenationResolver {
private indentationBag: IndentationBag;
private scriptBlockBeginLineNumber: number;
private offsetIndentationDeltas: Dictionary_int_int;
constructor(
public logger: TypeScript.ILogger,
public tree: ParseTree,
public snapshot: ITextSnapshot,
public languageHostIndentation: string,
public editorOptions: Services.EditorOptions,
public firstToken: TokenSpan,
public smartIndent: boolean) {
this.indentationBag = new IndentationBag(this.snapshot);
this.scriptBlockBeginLineNumber = -1;
this.offsetIndentationDeltas = new Dictionary_int_int(); // text offset -> indentation delta
// by default the root (program) has zero indendation
this.tree.Root.SetIndentationOverride("");
this.ApplyScriptBlockIndentation(this.languageHostIndentation, this.tree);
this.FillInheritedIndentation(this.tree);
}
public GetIndentationEdits(token: TokenSpan, nextToken: TokenSpan, node: ParseNode, sameLineIndent: boolean): List_TextEditInfo {
if (this.logger.information()) {
this.logger.log("GetIndentationEdits(" +
"t1=[" + token.Span.startPosition() + "," + token.Span.endPosition()+ "], " +
"t2=[" + (nextToken == null ? "null" : (nextToken.Span.startPosition() + "," + nextToken.Span.endPosition())) + "]" +
")");
}
var result = this.GetIndentationEditsWorker(token, nextToken, node, sameLineIndent);
if (this.logger.information()) {
for (var i = 0; i < result.count() ; i++) {
var edit = result.get(i);
this.logger.log("edit: minChar=" + edit.position + ", limChar=" + (edit.position + edit.length) + ", text=\"" + TypeScript.stringToLiteral(edit.replaceWith, 30) + "\"");
}
}
return result;
}
public GetIndentationEditsWorker(token: TokenSpan, nextToken: TokenSpan, node: ParseNode, sameLineIndent: boolean): List_TextEditInfo {
var result = new List_TextEditInfo();
var indentationInfo: IndentationInfo = null;
// This handles the case:
// return (
// function() {
// })
// The given function's node indicates that the function starts directly after "return (".
// In this case, we adjust the span to point to the function keyword.
// The same applies to objects and arrays.
// The reason this is done inside the Indenter is because it only affects indentation behavior.
// It's also done in ParseTree when we traverse up the tree because we don't have the
// tokens for nodes outside the span we are formatting.
this.AdjustStartOffsetIfNeeded(token, node);
// Don't adjust indentation on the same line of a script block
if (this.scriptBlockBeginLineNumber == token.lineNumber()) {
return result;
}
// Don't indent multi-line strings
if (!sameLineIndent && this.IsMultiLineString(token)) {
return result;
}
// Special cases for the tokens that don't show up in the tree, such as curly braces and comments
indentationInfo = this.GetSpecialCaseIndentation(token, node);
if (indentationInfo == null) {
//// For anything else
// Get the indentation level only from the node that starts on the same offset as the token
// otherwise the token is not meant to be indented
while (!node.CanIndent() && node.Parent != null && token.Span.span.start() == node.Parent.AuthorNode.Details.StartOffset)
node = node.Parent;
if (node.CanIndent() && token.Span.span.start() == node.AuthorNode.Details.StartOffset) {
indentationInfo = node.GetEffectiveIndentation(this);
}
else {
//// Special cases for anything else that is not in the tree and should be indented
// check for label (identifier followed by a colon)
if (token.Token == AuthorTokenKind.atkIdentifier && nextToken != null && nextToken.Token == AuthorTokenKind.atkColon) {
// This will make the label on the same level as the surrounding function/block
// ex:
// {
// statement;
// label:
// statement;
// }
indentationInfo = node.GetEffectiveChildrenIndentation(this);
}
else {
//// Move the token the same indentation-delta that moved its indentable parent
//// For example:
//// var a,
//// b;
//// The declaration 'b' would remain under 'a' even if 'var' got indented.
indentationInfo = this.ApplyIndentationDeltaFromParent(token, node);
}
}
}
// Get the indent edit from the indentation info
if (indentationInfo != null) {
var edit = this.GetIndentEdit(indentationInfo, token.Span.startPosition(), sameLineIndent);
if (edit != null) {
this.RegisterIndentation(edit, sameLineIndent);
result.add(edit);
// multi-line comments, apply delta indentation to all the other lines
if (token.Token == AuthorTokenKind.atkComment) {
var commentEdits = this.GetCommentIndentationEdits(token);
commentEdits.foreach((item) => {
result.add(item);
});
}
}
}
return result;
}
private GetCommentIndentationEdits(token: TokenSpan): List_TextEditInfo {
var result = new List_TextEditInfo();
if (token.Token != AuthorTokenKind.atkComment)
return result;
var commentLastLineNumber = this.snapshot.GetLineNumberFromPosition(token.Span.endPosition());
if (token.lineNumber() == commentLastLineNumber)
return result;
var commentFirstLineIndentationDelta = this.GetIndentationDelta(token.Span.startPosition(), null);
if (commentFirstLineIndentationDelta != undefined) {
for (var line = token.lineNumber() + 1; line <= commentLastLineNumber; line++) {
var lineStartPosition = this.snapshot.GetLineFromLineNumber(line).startPosition();
var lineIndent = this.GetLineIndentationForOffset(lineStartPosition);
var commentIndentationInfo = this.ApplyIndentationDelta2(lineIndent, commentFirstLineIndentationDelta);
if (commentIndentationInfo != null) {
var tokenStartPosition = lineStartPosition + lineIndent.length;
var commentIndentationEdit = this.GetIndentEdit(commentIndentationInfo, tokenStartPosition, false);
if (commentIndentationEdit != null) {
result.add(commentIndentationEdit);
}
}
}
}
return result;
}
static GetIndentSizeFromIndentText(indentText: string, editorOptions: Services.EditorOptions): number {
return GetIndentSizeFromText(indentText, editorOptions, /*includeNonIndentChars:*/ false);
}
static GetIndentSizeFromText(text: string, editorOptions: Services.EditorOptions, includeNonIndentChars: boolean): number {
var indentSize = 0;
for (var i = 0; i < text.length; i++) {
var c = text.charAt(i);
if (c == '\t')
indentSize = (indentSize + editorOptions.TabSize) - (indentSize % editorOptions.TabSize);
else if (c == ' ')
indentSize += 1;
else {
if (includeNonIndentChars)
indentSize += 1;
else
break;
}
}
return indentSize;
}
private GetSpecialCaseIndentation(token: TokenSpan, node: ParseNode): IndentationInfo {
var indentationInfo: IndentationInfo = null;
switch (token.Token) {
case AuthorTokenKind.atkLCurly: // { is not part of the tree
indentationInfo = this.GetSpecialCaseIndentationForLCurly(node);
return indentationInfo;
case AuthorTokenKind.atkElse: // else is not part of the tree
case AuthorTokenKind.atkRBrack: // ] is not part of the tree
indentationInfo = node.GetNodeStartLineIndentation(this);
return indentationInfo;
case AuthorTokenKind.atkRCurly: // } is not part of the tree
// if '}' is for a body-block, get indentation based on its parent.
if (node.AuthorNode.Details.Kind == AuthorParseNodeKind.apnkBlock && node.AuthorNode.EdgeLabel == AuthorParseNodeEdge.apneBody)
node = node.Parent;
indentationInfo = node.GetNodeStartLineIndentation(this);
return indentationInfo;
case AuthorTokenKind.atkWhile: // while (in do-while) is not part of the tree
if (node.AuthorNode.Details.Kind == AuthorParseNodeKind.apnkDoWhile) {
indentationInfo = node.GetNodeStartLineIndentation(this);
return indentationInfo;
}
return null;
case AuthorTokenKind.atkSColon:
return this.GetSpecialCaseIndentationForSemicolon(token, node);
case AuthorTokenKind.atkComment:
return this.GetSpecialCaseIndentationForComment(token, node);
default:
return indentationInfo;
}
}
private GetSpecialCaseIndentationForLCurly(node: ParseNode): IndentationInfo {
var indentationInfo: IndentationInfo = null;
if (node.AuthorNode.Details.Kind == AuthorParseNodeKind.apnkFncDecl ||
node.AuthorNode.EdgeLabel == AuthorParseNodeEdge.apneThen || node.AuthorNode.EdgeLabel == AuthorParseNodeEdge.apneElse) {
// flushed with the node (function & if)
indentationInfo = node.GetNodeStartLineIndentation(this);
return indentationInfo;
}
else if (node.AuthorNode.Details.Kind == AuthorParseNodeKind.apnkObject && !node.CanIndent()) {
// if the open curly belongs to a non-indented object, do nothing here.
return null;
}
// effective identation of the block
indentationInfo = node.GetEffectiveIndentation(this);
return indentationInfo;
}
private GetSpecialCaseIndentationForSemicolon(token: TokenSpan, node: ParseNode): IndentationInfo {
var indentationInfo: IndentationInfo = null;
if (this.smartIndent) {
indentationInfo = node.GetEffectiveChildrenIndentation(this);
return indentationInfo;
}
else {
// Indent all semicolons except the ones that belong to the for statement parts (initalizer, condition, itnrement)
if (node.AuthorNode.Details.Kind != AuthorParseNodeKind.apnkFor) {
// The passed node is actually either the program or the list because semicolon doesn't belong
// to any statement in the tree, though the statement extends up to the semicolon position.
// To find the correct statement, we look for the adjacent node on the left of the semicolon.
var semiColonStartSpan = new Span(token.Span.startPosition(), 0);
node = ParseTree.FindCommonParentNode(semiColonStartSpan, semiColonStartSpan, node);
indentationInfo = node.GetEffectiveChildrenIndentation(this);
return indentationInfo;
}
}
return null;
}
private GetSpecialCaseIndentationForComment(token: TokenSpan, node: ParseNode): IndentationInfo {
var indentationInfo: IndentationInfo = null;
// Only indent line comment and the first line of block comment
var twoCharSpan = token.Span.Intersection(new Span(token.Span.startPosition(), 2));
if (twoCharSpan != null && (twoCharSpan.GetText() == "//" || twoCharSpan.GetText() == "/*")) {
while (node.ChildrenIndentationDelta == null && node.Parent != null)
node = node.Parent;
if (this.CanIndentComment(token, node)) {
indentationInfo = node.GetEffectiveChildrenIndentationForComment(this);
}
else {
indentationInfo = this.ApplyIndentationDeltaFromParent(token, node);
}
}
return indentationInfo;
}
private CanIndentComment(token: TokenSpan, node: ParseNode): boolean {
switch (node.AuthorNode.Details.Kind) {
case AuthorParseNodeKind.apnkProg:
case AuthorParseNodeKind.apnkBlock:
case AuthorParseNodeKind.apnkSwitch:
case AuthorParseNodeKind.apnkCase:
case AuthorParseNodeKind.apnkDefaultCase:
case AuthorParseNodeKind.apnkIf:
case AuthorParseNodeKind.apnkFor:
case AuthorParseNodeKind.apnkForIn:
case AuthorParseNodeKind.apnkWhile:
case AuthorParseNodeKind.apnkWith:
case AuthorParseNodeKind.apnkDoWhile:
case AuthorParseNodeKind.apnkObject:
return true;
case AuthorParseNodeKind.apnkFncDecl:
// Comments before arguments are not indented.
// This code doesn't cover the cases of comment after the last argument or
// when there are no arguments. Though this is okay since the only case we care about is:
// function foo(/* test */ a,
// /* test */ b)
var result = true;
var children = ParseNodeExtensions.FindChildrenWithEdge(node, AuthorParseNodeEdge.apneArgument);
children.foreach((argumentNode) => {
if (token.Span.startPosition() < argumentNode.AuthorNode.Details.StartOffset)
result = false;
});
return result;
}
return false;
}
private ApplyScriptBlockIndentation(languageHostIndentation: string, tree: ParseTree): void
{
if (languageHostIndentation == null || tree.StartNodeSelf == null)
return;
var scriptBlockIndentation = this.ApplyIndentationLevel(languageHostIndentation, 1);
//TypeScript: Projection snapshots not supported
// Disconnect the sibling node if it belongs to a different script block
//IProjectionSnapshot projectionSnapshot = this.snapshot as IProjectionSnapshot;
//if (projectionSnapshot != null)
//{
// // Get script block spans.
// foreach (SnapshotSpan sourceSpan in projectionSnapshot.GetSourceSpans())
// {
// // Map the spans to the JavaScript buffer.
// ReadOnlyCollection<Span> spans = projectionSnapshot.MapFromSourceSnapshot(sourceSpan);
// Debug.Assert(spans.Count == 1, string.Format(CultureInfo.InvariantCulture, "Unexpected span count of {0}.", spans.Count));
// if (spans.Count > 0)
// {
// Span span = spans.First();
// // If the "self" node is the first root-level node in a script block, then remove the start node.
// if (span.Contains(tree.StartNodethis.AuthorNode.Details.StartOffset))
// {
// this.scriptBlockBeginLineNumber = projectionSnapshot.GetLineNumberFromPosition(span.Start);
// if (tree.StartNodePreviousSibling.HasValue)
// {
// int siblingStartOffset = tree.StartNodePreviousSibling.Value.Details.StartOffset;
// // Don't consider sibling in these cases:
// // 1. The sibling belongs to another script block
// // 2. The sibling is on the same line of the script block
// if (!span.Contains(siblingStartOffset) || projectionSnapshot.GetLineNumberFromPosition(siblingStartOffset) == this.scriptBlockBeginLineNumber)
// {
// tree.StartNodePreviousSibling = null;
// }
// }
// break;
// }
// }
// }
//}
// The root is the program.
tree.Root.SetIndentationOverride(scriptBlockIndentation);
}
private GetIndentEdit(indentInfo: IndentationInfo, tokenStartPosition: number, sameLineIndent: boolean): TextEditInfo {
var indentText = this.ApplyIndentationLevel(indentInfo.Prefix, indentInfo.Level);
if (sameLineIndent) {
return new TextEditInfo(tokenStartPosition, 0, indentText);
}
else {
var snapshotLine = this.snapshot.GetLineFromPosition(tokenStartPosition);
var currentIndentSpan = new Span(snapshotLine.startPosition(), tokenStartPosition - snapshotLine.startPosition());
var currentIndentText = this.snapshot.GetText(currentIndentSpan);
if (currentIndentText !== indentText) {
if (this.logger.debug()) {
// Verify that currentIndentText is all whitespaces
for (var i = 0, len = currentIndentText.length; i < len; i++) {
var c = currentIndentText.charCodeAt(i);
if (!StringUtils.IsWhiteSpace(c)) {
Debug.Fail("Formatting error: Will remove user code when indenting the line: " + snapshotLine.getText());
break;
}
}
}
return new TextEditInfo(currentIndentSpan.start(), currentIndentSpan.length(), indentText);
}
}
return null;
}
private ApplyIndentationLevel(existingIndentation: string, level: number): string {
var indentSize = this.editorOptions.IndentSize;
var tabSize = this.editorOptions.TabSize;
var convertTabsToSpaces = this.editorOptions.ConvertTabsToSpaces;
if (level < 0) {
if (StringUtils.IsNullOrEmpty(existingIndentation))
return "";
var totalIndent = 0;
StringUtils.foreach(existingIndentation, (c) => {
if (c == '\t')
totalIndent += tabSize;
else
totalIndent++;
});
totalIndent += level * indentSize;
if (totalIndent < 0)
return "";
else
return this.GetIndentString(null, totalIndent, tabSize, convertTabsToSpaces);
}
var totalIndentSize = level * indentSize;
return this.GetIndentString(existingIndentation, totalIndentSize, tabSize, convertTabsToSpaces);
}
private GetIndentString(prefix: string, totalIndentSize: number, tabSize: number, convertTabsToSpaces: boolean): string {
var tabString = convertTabsToSpaces ? StringUtils.create(' ', tabSize) : "\t";
var text = "";
if (!StringUtils.IsNullOrEmpty(prefix))
text += prefix;
var pos = 0;
// fill first with tabs
while (pos <= totalIndentSize - tabSize) {
text += tabString;
pos += tabSize;
}
// fill the reminder with spaces
while (pos < totalIndentSize) {
text += ' ';
pos++;
}
return text;
}
private ApplyIndentationDeltaFromParent(token: TokenSpan, node: ParseNode): IndentationInfo {
var indentationInfo: IndentationInfo = null;
var indentableParent = node;
while (indentableParent != null && !indentableParent.CanIndent())
indentableParent = indentableParent.Parent;
if (indentableParent != null && indentableParent.AuthorNode.Details.Kind != AuthorParseNodeKind.apnkProg) {
var parentIndentationDeltaSize = this.GetIndentationDelta(indentableParent.AuthorNode.Details.StartOffset, token.Span.startPosition());
if (parentIndentationDeltaSize !== undefined) {
indentationInfo = this.ApplyIndentationDelta1(token.Span.startPosition(), parentIndentationDeltaSize);
}
}
return indentationInfo;
}
private ApplyIndentationDelta1(tokenStartPosition: number, delta: number): IndentationInfo {
// Get current indentation
var snapshotLine = this.snapshot.GetLineFromPosition(tokenStartPosition);
var currentIndentSpan = new Span(snapshotLine.startPosition(), tokenStartPosition - snapshotLine.startPosition());
var currentIndent = this.snapshot.GetText(currentIndentSpan);
// Calculate new indentation from current-indentation and delta
return this.ApplyIndentationDelta2(currentIndent, delta);
}
private ApplyIndentationDelta2(currentIndent: string, delta: number): IndentationInfo {
if (delta == 0)
return null;
var currentIndentSize = Indenter.GetIndentSizeFromIndentText(currentIndent, this.editorOptions);
var newIndentSize = currentIndentSize + delta;
if (newIndentSize < 0) {
newIndentSize = 0;
}
var newIndent = this.GetIndentString(null, newIndentSize, this.editorOptions.TabSize, this.editorOptions.ConvertTabsToSpaces);
if (newIndent != null) {
return new IndentationInfo(newIndent, 0);
}
return null;
}
private GetIndentationDelta(tokenStartPosition: number, childTokenStartPosition: number/*?*/): number/*?*/ {
Debug.Assert(childTokenStartPosition !== undefined, "Error: caller must pass 'null' for undefined position");
var indentationDeltaSize = this.offsetIndentationDeltas.GetValue(tokenStartPosition);
if (indentationDeltaSize === null) {
var indentEditInfo = this.indentationBag.FindIndent(tokenStartPosition);
// No recorded indentation, return null
if (indentEditInfo == null)
return null;
var origIndentText = this.snapshot.GetText(new Span(indentEditInfo.OrigIndentPosition, indentEditInfo.OrigIndentLength()));
var newIndentText = indentEditInfo.Indentation();
var origIndentSize = Indenter.GetIndentSizeFromText(origIndentText, this.editorOptions, /*includeNonIndentChars*/true);
var newIndentSize = Indenter.GetIndentSizeFromIndentText(newIndentText, this.editorOptions);
// Check the child's position whether it's before the parent position
// if so indent the child based on the first token on the line as opposed to the parent position
//
// Example of relative to parent (not line), relative indentation should be "4 (newIndentSize) - 9 (indentSize up to for) = -5"
//
// if (1) { for (i = 0; i < 10; => if (1) {
// i++) { for (i = 0; i < 10;
// i++) {
//
// Example of relative to line, relative indentation should be "4 (newIndentSize) - 0 (indentSize up to if) = 4"
//
// if (1) { for (i = 0; i < 10; => if (1) {
// i++) { for (i = 0; i < 10;
// i++) {
if (childTokenStartPosition !== null) {
var childTokenLineStartPosition = this.snapshot.GetLineFromPosition(childTokenStartPosition).startPosition();
var childIndentText = this.snapshot.GetText(new Span(childTokenLineStartPosition, childTokenStartPosition - childTokenLineStartPosition));
var childIndentSize = Indenter.GetIndentSizeFromIndentText(childIndentText, this.editorOptions);
if (childIndentSize < origIndentSize)
origIndentSize = Indenter.GetIndentSizeFromIndentText(origIndentText, this.editorOptions);
}
indentationDeltaSize = newIndentSize - origIndentSize;
this.offsetIndentationDeltas.Add(tokenStartPosition, indentationDeltaSize);
}
return indentationDeltaSize;
}
private FillInheritedIndentation(tree: ParseTree): void
{
var offset = -1;
var indentNode: ParseNode = null;
if (tree.StartNodeSelf != null) {
if (!this.smartIndent && tree.StartNodePreviousSibling !== null && tree.StartNodeSelf.AuthorNode.Label == 0 && tree.StartNodePreviousSibling.Label == 0) {
indentNode = tree.StartNodeSelf;
offset = tree.StartNodePreviousSibling.Details.StartOffset;
// In case the sibling node is on the same line of a parent node, ex:
// case 1: a++;
// break;
// In this example, the sibling of break is a++ but a++ is on the same line of its parent.
var lineNum = this.snapshot.GetLineNumberFromPosition(offset);
var node = indentNode;
while (node.Parent != null && this.snapshot.GetLineNumberFromPosition(node.Parent.AuthorNode.Details.StartOffset) == lineNum) {
node = node.Parent;
if (node.CanIndent()) {
indentNode = node;
indentNode.IndentationDelta = 0;
}
}
}
else {
var parent: ParseNode;
// Otherwise base on parent indentation.
if (this.smartIndent) {
// in smartIndent the self node is the parent node since it's the closest node to the new line
// ... unless in case if the startNodeSelf represents the firstToken then we need to choose its parent
parent = tree.StartNodeSelf;
while (parent != null && parent.AuthorNode.Details.StartOffset == this.firstToken.Span.startPosition())
parent = parent.Parent;
}
else {
// Get the parent that is really on a different line from the self node
var startNodeLineNumber = this.snapshot.GetLineNumberFromPosition(tree.StartNodeSelf.AuthorNode.Details.StartOffset);
parent = tree.StartNodeSelf.Parent;
while (parent != null &&
startNodeLineNumber == this.snapshot.GetLineNumberFromPosition(parent.AuthorNode.Details.StartOffset)) {
parent = parent.Parent;
}
}
// The parent node to take its indentation is the first parent that has indentation.
while (parent != null && !parent.CanIndent()) {
parent = parent.Parent;
}
// Skip Program since it has no indentation
if (parent != null && parent.AuthorNode.Details.Kind != AuthorParseNodeKind.apnkProg) {
offset = parent.AuthorNode.Details.StartOffset;
indentNode = parent;
}
}
}
if (indentNode != null) {
var indentOverride = this.GetLineIndentationForOffset(offset);
// Set the indentation on all the siblings to be the same as indentNode
if (!this.smartIndent && tree.StartNodePreviousSibling !== null && indentNode.Parent != null) {
ParseNodeExtensions.GetChildren(indentNode.Parent).foreach((sibling) => {
if (sibling !== indentNode) {
if (sibling.CanIndent())
sibling.SetIndentationOverride(indentOverride);
}
});
}
// Set the indent override string on the indent node and on every parent (on different line) after adjusting the indent by the negative delta
var lastDelta = 0;
var lastLine = this.snapshot.GetLineNumberFromPosition(indentNode.AuthorNode.Details.StartOffset);
do {
var currentLine = this.snapshot.GetLineNumberFromPosition(indentNode.AuthorNode.Details.StartOffset);
if (lastLine != currentLine) {
lastLine = currentLine;
indentOverride = this.ApplyIndentationLevel(indentOverride, -lastDelta);
lastDelta = 0;
}
if (indentNode.CanIndent()) {
indentNode.SetIndentationOverride(indentOverride);
lastDelta = indentNode.IndentationDelta;
}
indentNode = indentNode.Parent;
}
while (indentNode != null);
}
}
public GetLineIndentationForOffset(offset: number): string {
var indentationEdit: IndentationEditInfo;
// First check if we already have indentation info in our indentation bag
indentationEdit = this.indentationBag.FindIndent(offset);
if (indentationEdit != null) {
return indentationEdit.Indentation();
}
else {
// Otherwise, use the indentation from the textBuffer
var line = this.snapshot.GetLineFromPosition(offset);
var lineText = line.getText();
var index = 0;
while (index < lineText.length && (lineText.charAt(index) == ' ' || lineText.charAt(index) == '\t')) {
++index;
}
return lineText.substr(0, index);
}
}
private RegisterIndentation(indent: TextEditInfo, sameLineIndent: boolean): void
{
var indentationInfo: IndentationEditInfo = null;
if (sameLineIndent) {
// Consider the original indentation from the beginning of the line up to the indent position (or really the token position)
var lineStartPosition = this.snapshot.GetLineFromPosition(indent.Position).startPosition();
var lineIndentLength = indent.Position - lineStartPosition;
indentationInfo = IndentationEditInfo.create2(indent.Position, indent.ReplaceWith, lineStartPosition, lineIndentLength);
}
else {
indentationInfo = new IndentationEditInfo(indent);
}
this.indentationBag.AddIndent(indentationInfo);
}
public RegisterIndentation2(position: number, indent: string): void
{
this.RegisterIndentation(new TextEditInfo(position, 0, indent), false);
}
private AdjustStartOffsetIfNeeded(token: TokenSpan, node: ParseNode): void
{
if (token == null)
return;
var updateStartOffset = false;
switch (token.Token) {
case AuthorTokenKind.atkFunction:
updateStartOffset = node.AuthorNode.Details.Kind == AuthorParseNodeKind.apnkFncDecl;
break;
case AuthorTokenKind.atkLCurly:
updateStartOffset = node.AuthorNode.Details.Kind == AuthorParseNodeKind.apnkObject;
break;
case AuthorTokenKind.atkLBrack:
updateStartOffset = node.AuthorNode.Details.Kind == AuthorParseNodeKind.apnkArray;
break;
}
if (updateStartOffset) {
ParseNodeExtensions.SetNodeSpan(node, token.Span.startPosition(), node.AuthorNode.Details.EndOffset);
}
}
private IsMultiLineString(token: TokenSpan): boolean {
return token.tokenID === TypeScript.TokenID.StringLiteral &&
this.snapshot.GetLineNumberFromPosition(token.Span.endPosition()) > this.snapshot.GetLineNumberFromPosition(token.Span.startPosition());
}
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parservoidInQualifiedName0.ts | TypeScript | var v : void; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/parservoidInQualifiedName2.ts | TypeScript | var v : x.void; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/partiallyAnnotatedFunctionInferenceError.ts | TypeScript | class C {
test: string
}
class D extends C {
test2: string
}
declare function testError<T extends C>(a: (t: T, t1: T) => void): T
// more args
testError((t1: D, t2, t3) => {})
testError((t1, t2: D, t3) => {})
testError((t1, t2, t3: D) => {})
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/partiallyAnnotatedFunctionInferenceWithTypeParameter.ts | TypeScript | class C {
test: string
}
class D extends C {
test2: string
}
declare function test<T extends C>(a: (t: T, t1: T) => void): T
declare function testRest<T extends C>(a: (t: T, t1: T, ...ts: T[]) => void): T
// exactly
test((t1: D, t2) => { t2.test2 })
test((t1, t2: D) => { t2.test2 })
// zero arg
test(() => {})
// fewer args
test((t1: D) => {})
// rest arg
test((...ts: D[]) => {})
// source function has rest arg
testRest((t1: D) => {})
testRest((t1, t2, t3) => {})
testRest((t1: D, t2, t3) => {})
testRest((t1, t2: D, t3) => {})
testRest((t2: D, ...t3) => {})
testRest((t2, ...t3: D[]) => {})
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/partiallyAnnotatedFunctionWitoutTypeParameter.ts | TypeScript | // @noImplicitAny: true
// simple case
declare function simple(f: (a: number, b: number) => void): {}
simple((a: number, b) => {})
simple((a, b: number) => {})
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/partiallyNamedTuples.ts | TypeScript | type NamedAndAnonymous = [a: string, number];
function fa1(...args: NamedAndAnonymous) {}
function fa2(a: NamedAndAnonymous, ...args: NamedAndAnonymous) {}
type NamedAnonymousMixed = [a: string, number, c: number, NamedAndAnonymous];
function fb1(...args: NamedAnonymousMixed) {}
function fb2(a: NamedAnonymousMixed, ...args: NamedAnonymousMixed) {}
function fb3(a: NamedAnonymousMixed, ...args: NamedAnonymousMixed[3]) {}
type ToAnonymousTuple<T extends unknown[]> = {
[K in keyof T]: [K, T[K], keyof T, T];
};
type AnonymousToAnonymous = ToAnonymousTuple<[boolean, number]>;
type MixedToAnonymous = ToAnonymousTuple<[boolean, second: number]>;
type NamedToAnonymous = ToAnonymousTuple<[first: boolean, second: number]>;
type ToMixedTuple<T extends unknown[]> = {
[K in keyof T]: [K, second: T[K], keyof T, fourth: T];
};
type AnonymousToMixed = ToMixedTuple<[boolean, number]>;
type MixedToMixed = ToMixedTuple<[boolean, second: number]>;
type NamedToMixed = ToMixedTuple<[first: boolean, second: number]>;
type MixedSpread = [first: boolean, ...[second: string]];
type ConditionalTuple = [
first: boolean,
...(0 extends 0 ? [second: string] : [])
];
type AddMixedConditional<T> = [
first: boolean,
null,
third: T extends number ? "a" : "b",
...(T extends 0 ? [fourth: "c"] : [])
];
type AddMixedConditionalBoolean = AddMixedConditional<boolean>;
type AddMixedConditionalLiteral = AddMixedConditional<0>;
type AddMixedConditionalNumberPrimitive = AddMixedConditional<number>;
declare function test<T extends readonly unknown[]>(
arg: [
...{
[K in keyof T]: {
type: T[K];
};
}
]
): T;
declare const input: [first: { type: number }, { type: string }];
const output = test(input);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/partiallyNamedTuples2.ts | TypeScript | // @strict: true
// @lib: esnext
// https://github.com/microsoft/TypeScript/issues/55693
interface MultiKeyMap<Keys extends readonly unknown[], Value> {
get<Key extends GetKeys<Keys>>(...key: Key): GetResult<Keys, Key, Value>;
}
type GetKeys<Keys extends readonly unknown[]> = Keys extends [
...infer Remain,
infer _,
]
? Keys | GetKeys<Remain>
: Keys;
type GetResult<
Id extends readonly unknown[],
Args extends GetKeys<Id>,
Value,
> = Args extends Id
? Value | undefined
: Id extends [...Args, ...infer Rest]
? Iterable<[...Rest, Value]>
: never;
const x: MultiKeyMap<[id1: string, id2: string], object> = null!;
const id1 = "abc" as string;
const matches = x.get(id1);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/partiallyNamedTuples3.ts | TypeScript | // @strict: true
// @lib: esnext
declare const tuple: [number, name: string, boolean, value: number, string];
const output = ((...args) => args)(...tuple);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/plainJSGrammarErrors2.ts | TypeScript | // @outdir: out/
// @target: esnext
// @module: esnext
// @allowJs: true
// @filename: plainJSGrammarErrors2.js
// @filename: /a.js
export default 1;
// @filename: /b.js
/**
* @deprecated
*/
export { default as A } from "./a";
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/plainJSGrammarErrors4.ts | TypeScript | // @outdir: out/
// @target: esnext
// @module: esnext
// @allowJs: true
// @filename: plainJSGrammarErrors4.js
class A {
#a;
m() {
this.#a; // ok
this.#b; // error
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/plainJSRedeclare.ts | TypeScript | // @outdir: out/
// @allowJS: true
// @filename: plainJSRedeclare.js
const orbitol = 1
var orbitol = 1 + false
orbitol.toExponential()
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/plainJSRedeclare2.ts | TypeScript | // @outdir: out/
// @allowJS: true
// @checkJS: true
// @filename: plainJSRedeclare.js
const orbitol = 1
var orbitol = 1 + false
orbitol.toExponential()
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/plainJSRedeclare3.ts | TypeScript | // @outdir: out/
// @allowJS: true
// @checkJS: false
// @filename: plainJSRedeclare.js
const orbitol = 1
var orbitol = 1 + false
orbitol.toExponential()
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/plainJSTypeErrors.ts | TypeScript | // @outdir: out/
// @target: esnext
// @allowJS: true
// @filename: plainJSTypeErrors.js
// should error
if ({} === {}) {}
// should not error
if ({} == {}) {}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/plusOperatorWithBooleanType.ts | TypeScript | // + operator on boolean type
var BOOLEAN: boolean;
function foo(): boolean { return true; }
class A {
public a: boolean;
static foo() { return false; }
}
module M {
export var n: boolean;
}
var objA = new A();
// boolean type var
var ResultIsNumber1 = +BOOLEAN;
// boolean type literal
var ResultIsNumber2 = +true;
var ResultIsNumber3 = +{ x: true, y: false };
// boolean type expressions
var ResultIsNumber4 = +objA.a;
var ResultIsNumber5 = +M.n;
var ResultIsNumber6 = +foo();
var ResultIsNumber7 = +A.foo();
// miss assignment operators
+true;
+BOOLEAN;
+foo();
+true, false;
+objA.a;
+M.n; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/plusOperatorWithEnumType.ts | TypeScript | // + operator on enum type
enum ENUM { };
enum ENUM1 { A, B, "" };
// enum type var
var ResultIsNumber1 = +ENUM;
var ResultIsNumber2 = +ENUM1;
// enum type expressions
var ResultIsNumber3 = +ENUM1["A"];
var ResultIsNumber4 = +(ENUM[0] + ENUM1["B"]);
// miss assignment operators
+ENUM;
+ENUM1;
+ENUM1.B;
+ENUM, ENUM1; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/plusOperatorWithNumberType.ts | TypeScript | // + operator on number type
var NUMBER: number;
var NUMBER1: number[] = [1, 2];
function foo(): number { return 1; }
class A {
public a: number;
static foo() { return 1; }
}
module M {
export var n: number;
}
var objA = new A();
// number type var
var ResultIsNumber1 = +NUMBER;
var ResultIsNumber2 = +NUMBER1;
// number type literal
var ResultIsNumber3 = +1;
var ResultIsNumber4 = +{ x: 1, y: 2};
var ResultIsNumber5 = +{ x: 1, y: (n: number) => { return n; } };
// number type expressions
var ResultIsNumber6 = +objA.a;
var ResultIsNumber7 = +M.n;
var ResultIsNumber8 = +NUMBER1[0];
var ResultIsNumber9 = +foo();
var ResultIsNumber10 = +A.foo();
var ResultIsNumber11 = +(NUMBER + NUMBER);
// miss assignment operators
+1;
+NUMBER;
+NUMBER1;
+foo();
+objA.a;
+M.n;
+objA.a, M.n; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/plusOperatorWithStringType.ts | TypeScript | // + operator on string type
var STRING: string;
var STRING1: string[] = ["", "abc"];
function foo(): string { return "abc"; }
class A {
public a: string;
static foo() { return ""; }
}
module M {
export var n: string;
}
var objA = new A();
// string type var
var ResultIsNumber1 = +STRING;
var ResultIsNumber2 = +STRING1;
// string type literal
var ResultIsNumber3 = +"";
var ResultIsNumber4 = +{ x: "", y: "" };
var ResultIsNumber5 = +{ x: "", y: (s: string) => { return s; } };
// string type expressions
var ResultIsNumber6 = +objA.a;
var ResultIsNumber7 = +M.n;
var ResultIsNumber8 = +STRING1[0];
var ResultIsNumber9 = +foo();
var ResultIsNumber10 = +A.foo();
var ResultIsNumber11 = +(STRING + STRING);
var ResultIsNumber12 = +STRING.charAt(0);
// miss assignment operators
+"";
+STRING;
+STRING1;
+foo();
+objA.a,M.n; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/preserveValueImports.ts | TypeScript | // @preserveValueImports: true
// @isolatedModules: true,false
// @module: esnext
// @Filename: a.ts
export default {};
export const b = 0;
export const c = 1;
export interface D {}
// @Filename: b.ts
import a, { b, c, D } from "./a";
// @Filename: c.ts
import * as a from "./a";
// @Filename: d.ts
export = {};
// @Filename: e.ts
import D = require("./d");
import DD = require("./d");
DD;
// @Filename: f.ts
import type a from "./a";
import { b, c } from "./a";
b;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/preserveValueImports_errors.ts | TypeScript | // @preserveValueImports: true
// @isolatedModules: true,false
// @module: esnext
// @Filename: a.ts
export type A = {};
export type { A as default };
// @Filename: b.ts
class B {};
export type { B, B as default };
// @Filename: c.ts
import DefaultA from "./a";
import { A } from "./a";
import DefaultB from "./b";
import { B } from "./b";
// @Filename: c.fixed.ts
import type DefaultA from "./a";
import type { A } from "./a";
import type DefaultB from "./b";
import type { B } from "./b";
// @Filename: d.ts
export { A as AA } from "./a";
export { B as BB } from "./b";
// @Filename: d.fixed.ts
export type { A as AA } from "./a";
export type { B as BB } from "./b";
// @Filename: e.ts
import { AA, BB } from "./d";
// @Filename: e.fixed.ts
import type { AA, BB } from "./d";
// @Filename: f.ts
import type { A } from "./a";
import type { B } from "./b";
export { A, B as BB };
// @Filename: f.fixed.ts
import type { A } from "./a";
import type { B } from "./b";
export type { A, B as BB };
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/preserveValueImports_importsNotUsedAsValues.ts | TypeScript | // @preserveValueImports: true
// @importsNotUsedAsValues: preserve
// @module: esnext
// @Filename: /mod.ts
export type A = unknown;
export type B = never;
export type C = any;
// @Filename: /index.ts
import { type A, type B, type C } from "./mod.js";
// @Filename: /reexport.ts
export { type A, type B, type C } from "./mod.js";
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/preserveValueImports_mixedImports.ts | TypeScript | // @preserveValueImports: true
// @isolatedModules: true
// @module: es2015
// @Filename: /exports.ts
export function Component() {}
export interface ComponentProps {}
// @Filename: /index.ts
import { Component, ComponentProps } from "./exports.js";
// @Filename: /index.fixed.ts
import { Component, type ComponentProps } from "./exports.js";
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/preserveValueImports_module.ts | TypeScript | // @preserveValueImports: true
// @module: amd,system,commonjs,es2015
// @noTypesAndSymbols: true
export {};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/primtiveTypesAreIdentical.ts | TypeScript | // primitive types are identical to themselves so these overloads will all cause errors
function foo1(x: number);
function foo1(x: number);
function foo1(x: any) { }
function foo2(x: string);
function foo2(x: string);
function foo2(x: any) { }
function foo3(x: boolean);
function foo3(x: boolean);
function foo3(x: any) { }
function foo4(x: any);
function foo4(x: any);
function foo4(x: any) { }
function foo5(x: 'a');
function foo5(x: 'a');
function foo5(x: string);
function foo5(x: any) { }
enum E { A }
function foo6(x: E);
function foo6(x: E);
function foo6(x: any) { }
function foo7(x: void);
function foo7(x: void);
function foo7(x: any) { } | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/privateClassPropertyAccessibleWithinClass.ts | TypeScript | // no errors
class C {
private x: string;
private get y() { return this.x; }
private set y(x) { this.y = this.x; }
private foo() { return this.foo; }
private static x: string;
private static get y() { return this.x; }
private static set y(x) { this.y = this.x; }
private static foo() { return this.foo; }
private static bar() { this.foo(); }
}
// added level of function nesting
class C2 {
private x: string;
private get y() { () => this.x; return null; }
private set y(x) { () => { this.y = this.x; } }
private foo() { () => this.foo; }
private static x: string;
private static get y() { () => this.x; return null; }
private static set y(x) {
() => { this.y = this.x; }
}
private static foo() { () => this.foo; }
private static bar() { () => this.foo(); }
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/privateClassPropertyAccessibleWithinNestedClass.ts | TypeScript | // @target: ES5
// no errors
class C {
private x: string;
private get y() { return this.x; }
private set y(x) { this.y = this.x; }
private foo() { return this.foo; }
private static x: string;
private static get y() { return this.x; }
private static set y(x) { this.y = this.x; }
private static foo() { return this.foo; }
private static bar() { this.foo(); }
private bar() {
class C2 {
private foo() {
let x: C;
var x1 = x.foo;
var x2 = x.bar;
var x3 = x.x;
var x4 = x.y;
var sx1 = C.x;
var sx2 = C.y;
var sx3 = C.bar;
var sx4 = C.foo;
let y = new C();
var y1 = y.foo;
var y2 = y.bar;
var y3 = y.x;
var y4 = y.y;
}
}
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/privateConstructorFunction.ts | TypeScript | // @allowjs: true
// @checkjs: true
// @outdir: salsa
// @declaration: true
// @filename: privateConstructorFunction.js
{
// make sure not to crash when parent's a block rather than a source file or some other
// symbol-having node.
/** @private */
function C() {
this.x = 1
}
new C()
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/privateIdentifierExpando.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @declaration: true
// @emitDeclarationOnly: true
// @Filename: privateIdentifierExpando.js
const x = {};
x.#bar.baz = 20;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/privateNameAccessors.ts | TypeScript | // @strict: true
// @target: es6
class A1 {
get #prop() { return ""; }
set #prop(param: string) { }
get #roProp() { return ""; }
constructor(name: string) {
this.#prop = "";
this.#roProp = ""; // Error
console.log(this.#prop);
console.log(this.#roProp);
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/privateNameAccessorsCallExpression.ts | TypeScript | // @target: es2015
class A {
get #fieldFunc() { return function() { this.x = 10; } }
get #fieldFunc2() { return function(a, ...b) {}; }
x = 1;
test() {
this.#fieldFunc();
const func = this.#fieldFunc;
func();
new this.#fieldFunc();
const arr = [ 1, 2 ];
this.#fieldFunc2(0, ...arr, 3);
const b = new this.#fieldFunc2(0, ...arr, 3);
const str = this.#fieldFunc2`head${1}middle${2}tail`;
this.getInstance().#fieldFunc2`test${1}and${2}`;
}
getInstance() { return new A(); }
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/privateNameAmbientNoImplicitAny.ts | TypeScript | // @noImplicitAny: true
// @target: ESNext
declare class A {
#prop;
}
class B {
#prop;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/privateNameAndAny.ts | TypeScript | // @strict: true
// @target: es6
class A {
#foo = true;
static #baz = 10;
static #m() {}
method(thing: any) {
thing.#foo; // OK
thing.#m();
thing.#baz;
thing.#bar; // Error
thing.#foo();
}
methodU(thing: unknown) {
thing.#foo;
thing.#m();
thing.#baz;
thing.#bar;
thing.#foo();
}
methodN(thing: never) {
thing.#foo;
thing.#m();
thing.#baz;
thing.#bar;
thing.#foo();
}
};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/privateNameAndIndexSignature.ts | TypeScript | // @strict: true
// @target: es6
class A {
[k: string]: any;
#foo = 3;
["#bar"] = this["#bar"] // Error (private identifiers should not prevent circularity checking for computeds)
constructor(message: string) {
this.#f = 3 // Error (index signatures do not implicitly declare private names)
this["#foo"] = 3; // Okay (type has index signature and "#foo" does not collide with private identifier #foo)
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/privateNameAndObjectRestSpread.ts | TypeScript | // @strict: true
// @target: es6
class C {
#prop = 1;
static #propStatic = 1;
method(other: C) {
const obj = { ...other };
obj.#prop;
const { ...rest } = other;
rest.#prop;
const statics = { ... C};
statics.#propStatic
const { ...sRest } = C;
sRest.#propStatic;
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/privateNameAndStaticInitializer.ts | TypeScript | // @target: esnext, es2022, es2015
class A {
#foo = 1;
static inst = new A();
#prop = 2;
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/privateNameCircularReference.ts | TypeScript | // @strict: true
// @target: es6
class A {
#foo = this.#bar;
#bar = this.#foo;
["#baz"] = this["#baz"]; // Error (should *not* be private name error)
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/privateNameClassExpressionLoop.ts | TypeScript | // @target: es2015
const array = [];
for (let i = 0; i < 10; ++i) {
array.push(class C {
#myField = "hello";
#method() {}
get #accessor() { return 42; }
set #accessor(val) { }
});
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.