style(compiler): reformat of codebase with new clang-format version (#36520)
This commit reformats the packages/compiler tree using the new version of clang-format. PR Close #36520
This commit is contained in:
@ -18,14 +18,16 @@ import {extractSourceMap, originalPositionFor} from '@angular/compiler/testing/s
|
||||
const fileB = new ParseSourceFile('b0b1b2b3b4b5b6b7b8b9', 'b.js');
|
||||
let ctx: EmitterVisitorContext;
|
||||
|
||||
beforeEach(() => { ctx = EmitterVisitorContext.createRoot(); });
|
||||
beforeEach(() => {
|
||||
ctx = EmitterVisitorContext.createRoot();
|
||||
});
|
||||
|
||||
it('should add source files to the source map', () => {
|
||||
ctx.print(createSourceSpan(fileA, 0), 'o0');
|
||||
ctx.print(createSourceSpan(fileA, 1), 'o1');
|
||||
ctx.print(createSourceSpan(fileB, 0), 'o2');
|
||||
ctx.print(createSourceSpan(fileB, 1), 'o3');
|
||||
const sm = ctx.toSourceMapGenerator('o.ts').toJSON() !;
|
||||
const sm = ctx.toSourceMapGenerator('o.ts').toJSON()!;
|
||||
expect(sm.sources).toEqual([fileA.url, fileB.url]);
|
||||
expect(sm.sourcesContent).toEqual([fileA.content, fileB.content]);
|
||||
});
|
||||
@ -43,7 +45,7 @@ import {extractSourceMap, originalPositionFor} from '@angular/compiler/testing/s
|
||||
it('should be able to shift the content', () => {
|
||||
ctx.print(createSourceSpan(fileA, 0), 'fileA-0');
|
||||
|
||||
const sm = ctx.toSourceMapGenerator('o.ts', 10).toJSON() !;
|
||||
const sm = ctx.toSourceMapGenerator('o.ts', 10).toJSON()!;
|
||||
expect(originalPositionFor(sm, {line: 11, column: 0})).toEqual({
|
||||
line: 1,
|
||||
column: 0,
|
||||
@ -111,9 +113,9 @@ import {extractSourceMap, originalPositionFor} from '@angular/compiler/testing/s
|
||||
// All lines / columns indexes are 0-based
|
||||
// Note: source-map line indexes are 1-based, column 0-based
|
||||
function expectMap(
|
||||
ctx: EmitterVisitorContext, genLine: number, genCol: number, source: string | null = null,
|
||||
srcLine: number | null = null, srcCol: number | null = null) {
|
||||
const sm = ctx.toSourceMapGenerator('o.ts').toJSON() !;
|
||||
ctx: EmitterVisitorContext, genLine: number, genCol: number, source: string|null = null,
|
||||
srcLine: number|null = null, srcCol: number|null = null) {
|
||||
const sm = ctx.toSourceMapGenerator('o.ts').toJSON()!;
|
||||
const genPosition = {line: genLine + 1, column: genCol};
|
||||
const origPosition = originalPositionFor(sm, genPosition);
|
||||
// TODO: Review use of `any` here (#19904)
|
||||
@ -124,7 +126,7 @@ function expectMap(
|
||||
|
||||
// returns the number of segments per line
|
||||
function nbSegmentsPerLine(ctx: EmitterVisitorContext) {
|
||||
const sm = ctx.toSourceMapGenerator('o.ts').toJSON() !;
|
||||
const sm = ctx.toSourceMapGenerator('o.ts').toJSON()!;
|
||||
const lines = sm.mappings.split(';');
|
||||
return lines.map(l => {
|
||||
const m = l.match(/,/g);
|
||||
|
@ -11,24 +11,34 @@ import {escapeIdentifier} from '@angular/compiler/src/output/abstract_emitter';
|
||||
{
|
||||
describe('AbstractEmitter', () => {
|
||||
describe('escapeIdentifier', () => {
|
||||
it('should escape single quotes',
|
||||
() => { expect(escapeIdentifier(`'`, false)).toEqual(`'\\''`); });
|
||||
it('should escape single quotes', () => {
|
||||
expect(escapeIdentifier(`'`, false)).toEqual(`'\\''`);
|
||||
});
|
||||
|
||||
it('should escape backslash',
|
||||
() => { expect(escapeIdentifier('\\', false)).toEqual(`'\\\\'`); });
|
||||
it('should escape backslash', () => {
|
||||
expect(escapeIdentifier('\\', false)).toEqual(`'\\\\'`);
|
||||
});
|
||||
|
||||
it('should escape newlines',
|
||||
() => { expect(escapeIdentifier('\n', false)).toEqual(`'\\n'`); });
|
||||
it('should escape newlines', () => {
|
||||
expect(escapeIdentifier('\n', false)).toEqual(`'\\n'`);
|
||||
});
|
||||
|
||||
it('should escape carriage returns',
|
||||
() => { expect(escapeIdentifier('\r', false)).toEqual(`'\\r'`); });
|
||||
it('should escape carriage returns', () => {
|
||||
expect(escapeIdentifier('\r', false)).toEqual(`'\\r'`);
|
||||
});
|
||||
|
||||
it('should escape $', () => { expect(escapeIdentifier('$', true)).toEqual(`'\\$'`); });
|
||||
it('should not escape $', () => { expect(escapeIdentifier('$', false)).toEqual(`'$'`); });
|
||||
it('should add quotes for non-identifiers',
|
||||
() => { expect(escapeIdentifier('==', false, false)).toEqual(`'=='`); });
|
||||
it('does not escape class (but it probably should)',
|
||||
() => { expect(escapeIdentifier('class', false, false)).toEqual('class'); });
|
||||
it('should escape $', () => {
|
||||
expect(escapeIdentifier('$', true)).toEqual(`'\\$'`);
|
||||
});
|
||||
it('should not escape $', () => {
|
||||
expect(escapeIdentifier('$', false)).toEqual(`'$'`);
|
||||
});
|
||||
it('should add quotes for non-identifiers', () => {
|
||||
expect(escapeIdentifier('==', false, false)).toEqual(`'=='`);
|
||||
});
|
||||
it('does not escape class (but it probably should)', () => {
|
||||
expect(escapeIdentifier('class', false, false)).toEqual('class');
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -22,12 +22,14 @@ const someGenFilePath = 'somePackage/someGenFile';
|
||||
let emitter: JavaScriptEmitter;
|
||||
let someVar: o.ReadVarExpr;
|
||||
|
||||
beforeEach(() => { emitter = new JavaScriptEmitter(); });
|
||||
beforeEach(() => {
|
||||
emitter = new JavaScriptEmitter();
|
||||
});
|
||||
|
||||
function emitSourceMap(stmt: o.Statement | o.Statement[], preamble?: string): SourceMap {
|
||||
function emitSourceMap(stmt: o.Statement|o.Statement[], preamble?: string): SourceMap {
|
||||
const stmts = Array.isArray(stmt) ? stmt : [stmt];
|
||||
const source = emitter.emitStatements(someGenFilePath, stmts, preamble);
|
||||
return extractSourceMap(source) !;
|
||||
return extractSourceMap(source)!;
|
||||
}
|
||||
|
||||
describe('source maps', () => {
|
||||
|
@ -171,8 +171,9 @@ const externalModuleIdentifier = new o.ExternalReference(anotherModuleUrl, 'some
|
||||
});
|
||||
|
||||
it('should support function statements', () => {
|
||||
expect(emitStmt(new o.DeclareFunctionStmt('someFn', [], [
|
||||
]))).toEqual(['function someFn() {', '}'].join('\n'));
|
||||
expect(emitStmt(new o.DeclareFunctionStmt('someFn', [], []))).toEqual([
|
||||
'function someFn() {', '}'
|
||||
].join('\n'));
|
||||
expect(emitStmt(new o.DeclareFunctionStmt('someFn', [], [], null, [o.StmtModifier.Exported])))
|
||||
.toEqual([
|
||||
'function someFn() {', '}',
|
||||
@ -181,8 +182,9 @@ const externalModuleIdentifier = new o.ExternalReference(anotherModuleUrl, 'some
|
||||
expect(emitStmt(new o.DeclareFunctionStmt('someFn', [], [
|
||||
new o.ReturnStatement(o.literal(1))
|
||||
]))).toEqual(['function someFn() {', ' return 1;', '}'].join('\n'));
|
||||
expect(emitStmt(new o.DeclareFunctionStmt('someFn', [new o.FnParam('param1')], [
|
||||
]))).toEqual(['function someFn(param1) {', '}'].join('\n'));
|
||||
expect(emitStmt(new o.DeclareFunctionStmt('someFn', [new o.FnParam('param1')], []))).toEqual([
|
||||
'function someFn(param1) {', '}'
|
||||
].join('\n'));
|
||||
});
|
||||
|
||||
it('should support comments', () => {
|
||||
@ -219,25 +221,29 @@ const externalModuleIdentifier = new o.ExternalReference(anotherModuleUrl, 'some
|
||||
].join('\n'));
|
||||
});
|
||||
|
||||
it('should support support throwing',
|
||||
() => { expect(emitStmt(new o.ThrowStmt(someVar))).toEqual('throw someVar;'); });
|
||||
it('should support support throwing', () => {
|
||||
expect(emitStmt(new o.ThrowStmt(someVar))).toEqual('throw someVar;');
|
||||
});
|
||||
|
||||
describe('classes', () => {
|
||||
let callSomeMethod: o.Statement;
|
||||
|
||||
beforeEach(() => { callSomeMethod = o.THIS_EXPR.callMethod('someMethod', []).toStmt(); });
|
||||
beforeEach(() => {
|
||||
callSomeMethod = o.THIS_EXPR.callMethod('someMethod', []).toStmt();
|
||||
});
|
||||
|
||||
it('should support declaring classes', () => {
|
||||
expect(emitStmt(new o.ClassStmt('SomeClass', null !, [], [], null !, [
|
||||
]))).toEqual(['function SomeClass() {', '}'].join('\n'));
|
||||
expect(emitStmt(new o.ClassStmt('SomeClass', null!, [], [], null!, []))).toEqual([
|
||||
'function SomeClass() {', '}'
|
||||
].join('\n'));
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null !, [], [], null !, [], [o.StmtModifier.Exported])))
|
||||
'SomeClass', null!, [], [], null!, [], [o.StmtModifier.Exported])))
|
||||
.toEqual([
|
||||
'function SomeClass() {', '}',
|
||||
`Object.defineProperty(exports, 'SomeClass', { get: function() { return SomeClass; }});`
|
||||
].join('\n'));
|
||||
expect(emitStmt(
|
||||
new o.ClassStmt('SomeClass', o.variable('SomeSuperClass'), [], [], null !, [])))
|
||||
expect(
|
||||
emitStmt(new o.ClassStmt('SomeClass', o.variable('SomeSuperClass'), [], [], null!, [])))
|
||||
.toEqual([
|
||||
'function SomeClass() {', '}',
|
||||
'SomeClass.prototype = Object.create(SomeSuperClass.prototype);'
|
||||
@ -247,23 +253,22 @@ const externalModuleIdentifier = new o.ExternalReference(anotherModuleUrl, 'some
|
||||
it('should support declaring constructors', () => {
|
||||
const superCall = o.SUPER_EXPR.callFn([o.variable('someParam')]).toStmt();
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null !, [], [], new o.ClassMethod(null !, [], []), [])))
|
||||
'SomeClass', null!, [], [], new o.ClassMethod(null!, [], []), [])))
|
||||
.toEqual(['function SomeClass() {', '}'].join('\n'));
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null !, [], [],
|
||||
new o.ClassMethod(null !, [new o.FnParam('someParam')], []), [])))
|
||||
'SomeClass', null!, [], [],
|
||||
new o.ClassMethod(null!, [new o.FnParam('someParam')], []), [])))
|
||||
.toEqual(['function SomeClass(someParam) {', '}'].join('\n'));
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', o.variable('SomeSuperClass'), [], [],
|
||||
new o.ClassMethod(null !, [], [superCall]), [])))
|
||||
new o.ClassMethod(null!, [], [superCall]), [])))
|
||||
.toEqual([
|
||||
'function SomeClass() {', ' var self = this;',
|
||||
' SomeSuperClass.call(this, someParam);', '}',
|
||||
'SomeClass.prototype = Object.create(SomeSuperClass.prototype);'
|
||||
].join('\n'));
|
||||
expect(
|
||||
emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null !, [], [], new o.ClassMethod(null !, [], [callSomeMethod]), [])))
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null!, [], [], new o.ClassMethod(null!, [], [callSomeMethod]), [])))
|
||||
.toEqual([
|
||||
'function SomeClass() {', ' var self = this;', ' self.someMethod();', '}'
|
||||
].join('\n'));
|
||||
@ -271,14 +276,14 @@ const externalModuleIdentifier = new o.ExternalReference(anotherModuleUrl, 'some
|
||||
|
||||
it('should support declaring getters', () => {
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null !, [], [new o.ClassGetter('someGetter', [])], null !, [])))
|
||||
'SomeClass', null!, [], [new o.ClassGetter('someGetter', [])], null!, [])))
|
||||
.toEqual([
|
||||
'function SomeClass() {', '}',
|
||||
`Object.defineProperty(SomeClass.prototype, 'someGetter', { get: function() {`, `}});`
|
||||
].join('\n'));
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null !, [], [new o.ClassGetter('someGetter', [callSomeMethod])],
|
||||
null !, [])))
|
||||
'SomeClass', null!, [], [new o.ClassGetter('someGetter', [callSomeMethod])],
|
||||
null!, [])))
|
||||
.toEqual([
|
||||
'function SomeClass() {', '}',
|
||||
`Object.defineProperty(SomeClass.prototype, 'someGetter', { get: function() {`,
|
||||
@ -288,19 +293,19 @@ const externalModuleIdentifier = new o.ExternalReference(anotherModuleUrl, 'some
|
||||
|
||||
it('should support methods', () => {
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null !, [], [], null !, [new o.ClassMethod('someMethod', [], [])])))
|
||||
'SomeClass', null!, [], [], null!, [new o.ClassMethod('someMethod', [], [])])))
|
||||
.toEqual([
|
||||
'function SomeClass() {', '}', 'SomeClass.prototype.someMethod = function() {', '};'
|
||||
].join('\n'));
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null !, [], [], null !,
|
||||
'SomeClass', null!, [], [], null!,
|
||||
[new o.ClassMethod('someMethod', [new o.FnParam('someParam')], [])])))
|
||||
.toEqual([
|
||||
'function SomeClass() {', '}',
|
||||
'SomeClass.prototype.someMethod = function(someParam) {', '};'
|
||||
].join('\n'));
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null !, [], [], null !,
|
||||
'SomeClass', null!, [], [], null!,
|
||||
[new o.ClassMethod('someMethod', [], [callSomeMethod])])))
|
||||
.toEqual([
|
||||
'function SomeClass() {', '}', 'SomeClass.prototype.someMethod = function() {',
|
||||
|
@ -15,8 +15,8 @@ import * as o from '../../src/output/output_ast';
|
||||
const ref1 = new o.ExternalReference('aModule', 'name1');
|
||||
const ref2 = new o.ExternalReference('aModule', 'name2');
|
||||
const stmt =
|
||||
o.variable('test').set(o.NULL_EXPR).toDeclStmt(o.importType(ref1, [o.importType(
|
||||
ref2) !]));
|
||||
o.variable('test').set(o.NULL_EXPR).toDeclStmt(o.importType(ref1, [o.importType(ref2)!
|
||||
]));
|
||||
|
||||
expect(o.collectExternalReferences([stmt])).toEqual([ref1, ref2]);
|
||||
});
|
||||
|
@ -57,7 +57,7 @@ const anotherModuleUrl = 'somePackage/someOtherPath';
|
||||
o.literal('use strict').toStmt(),
|
||||
],
|
||||
ctx);
|
||||
const matches = ctx.toSource().match(/'use strict';/g) !;
|
||||
const matches = ctx.toSource().match(/'use strict';/g)!;
|
||||
expect(matches.length).toBe(1);
|
||||
});
|
||||
});
|
||||
|
@ -52,7 +52,7 @@ import {SourceMapGenerator, toBase64String} from '@angular/compiler/src/output/s
|
||||
.addMapping(3, 'a.js', 5, 2);
|
||||
|
||||
// Generated with https://sokra.github.io/source-map-visualization using a TS source map
|
||||
expect(map.toJSON() !.mappings)
|
||||
expect(map.toJSON()!.mappings)
|
||||
.toEqual(
|
||||
'AAAA,IAAM,CAAC,GAAe,CAAC,CAAC;AACxB,IAAM,CAAC,GAAG,CAAC,CAAC;AAEZ,EAAE,CAAC,OAAO,CAAC,UAAA,CAAC;IACR,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC,CAAC,CAAA');
|
||||
});
|
||||
@ -64,7 +64,7 @@ import {SourceMapGenerator, toBase64String} from '@angular/compiler/src/output/s
|
||||
.addSource('url.ts', null)
|
||||
.addLine()
|
||||
.addMapping(0, 'inline.ts', 0, 0)
|
||||
.toJSON() !;
|
||||
.toJSON()!;
|
||||
|
||||
expect(map.file).toEqual('out.js');
|
||||
expect(map.sources).toEqual(['inline.ts', 'url.ts']);
|
||||
@ -81,7 +81,11 @@ import {SourceMapGenerator, toBase64String} from '@angular/compiler/src/output/s
|
||||
|
||||
describe('encodeB64String', () => {
|
||||
it('should return the b64 encoded value', () => {
|
||||
[['', ''], ['a', 'YQ=='], ['Foo', 'Rm9v'], ['Foo1', 'Rm9vMQ=='], ['Foo12', 'Rm9vMTI='],
|
||||
[['', ''],
|
||||
['a', 'YQ=='],
|
||||
['Foo', 'Rm9v'],
|
||||
['Foo1', 'Rm9vMQ=='],
|
||||
['Foo12', 'Rm9vMTI='],
|
||||
['Foo123', 'Rm9vMTIz'],
|
||||
].forEach(([src, b64]) => expect(toBase64String(src)).toEqual(b64));
|
||||
});
|
||||
@ -113,7 +117,7 @@ import {SourceMapGenerator, toBase64String} from '@angular/compiler/src/output/s
|
||||
|
||||
it('should throw when adding segments without column', () => {
|
||||
expect(() => {
|
||||
new SourceMapGenerator('out.js').addSource('in.js').addLine().addMapping(null !);
|
||||
new SourceMapGenerator('out.js').addSource('in.js').addLine().addMapping(null!);
|
||||
}).toThrowError('The column in the generated code must be provided');
|
||||
});
|
||||
|
||||
|
@ -31,10 +31,10 @@ const someGenFilePath = 'somePackage/someGenFile';
|
||||
someVar = o.variable('someVar');
|
||||
});
|
||||
|
||||
function emitSourceMap(stmt: o.Statement | o.Statement[], preamble?: string): SourceMap {
|
||||
function emitSourceMap(stmt: o.Statement|o.Statement[], preamble?: string): SourceMap {
|
||||
const stmts = Array.isArray(stmt) ? stmt : [stmt];
|
||||
const source = emitter.emitStatements(someGenFilePath, stmts, preamble);
|
||||
return extractSourceMap(source) !;
|
||||
return extractSourceMap(source)!;
|
||||
}
|
||||
|
||||
describe('source maps', () => {
|
||||
|
@ -35,7 +35,7 @@ const externalModuleIdentifier = new o.ExternalReference(anotherModuleUrl, 'some
|
||||
someVar = o.variable('someVar', null, null);
|
||||
});
|
||||
|
||||
function emitStmt(stmt: o.Statement | o.Statement[], preamble?: string): string {
|
||||
function emitStmt(stmt: o.Statement|o.Statement[], preamble?: string): string {
|
||||
const stmts = Array.isArray(stmt) ? stmt : [stmt];
|
||||
const source = emitter.emitStatements(someGenFilePath, stmts, preamble);
|
||||
return stripSourceMapAndNewLine(source);
|
||||
@ -223,15 +223,17 @@ const externalModuleIdentifier = new o.ExternalReference(anotherModuleUrl, 'some
|
||||
});
|
||||
|
||||
it('should support function statements', () => {
|
||||
expect(emitStmt(new o.DeclareFunctionStmt('someFn', [], [
|
||||
]))).toEqual(['function someFn():void {', '}'].join('\n'));
|
||||
expect(emitStmt(new o.DeclareFunctionStmt('someFn', [], []))).toEqual([
|
||||
'function someFn():void {', '}'
|
||||
].join('\n'));
|
||||
expect(emitStmt(new o.DeclareFunctionStmt('someFn', [], [], null, [o.StmtModifier.Exported])))
|
||||
.toEqual(['export function someFn():void {', '}'].join('\n'));
|
||||
expect(emitStmt(new o.DeclareFunctionStmt(
|
||||
'someFn', [], [new o.ReturnStatement(o.literal(1))], o.INT_TYPE)))
|
||||
.toEqual(['function someFn():number {', ' return 1;', '}'].join('\n'));
|
||||
expect(emitStmt(new o.DeclareFunctionStmt('someFn', [new o.FnParam('param1', o.INT_TYPE)], [
|
||||
]))).toEqual(['function someFn(param1:number):void {', '}'].join('\n'));
|
||||
expect(
|
||||
emitStmt(new o.DeclareFunctionStmt('someFn', [new o.FnParam('param1', o.INT_TYPE)], [])))
|
||||
.toEqual(['function someFn(param1:number):void {', '}'].join('\n'));
|
||||
});
|
||||
|
||||
it('should support comments', () => {
|
||||
@ -266,43 +268,47 @@ const externalModuleIdentifier = new o.ExternalReference(anotherModuleUrl, 'some
|
||||
].join('\n'));
|
||||
});
|
||||
|
||||
it('should support support throwing',
|
||||
() => { expect(emitStmt(new o.ThrowStmt(someVar))).toEqual('throw someVar;'); });
|
||||
it('should support support throwing', () => {
|
||||
expect(emitStmt(new o.ThrowStmt(someVar))).toEqual('throw someVar;');
|
||||
});
|
||||
|
||||
describe('classes', () => {
|
||||
let callSomeMethod: o.Statement;
|
||||
|
||||
beforeEach(() => { callSomeMethod = o.THIS_EXPR.callMethod('someMethod', []).toStmt(); });
|
||||
beforeEach(() => {
|
||||
callSomeMethod = o.THIS_EXPR.callMethod('someMethod', []).toStmt();
|
||||
});
|
||||
|
||||
|
||||
it('should support declaring classes', () => {
|
||||
expect(emitStmt(new o.ClassStmt('SomeClass', null !, [], [], null !, [
|
||||
]))).toEqual(['class SomeClass {', '}'].join('\n'));
|
||||
expect(emitStmt(new o.ClassStmt('SomeClass', null !, [], [], null !, [], [
|
||||
expect(emitStmt(new o.ClassStmt('SomeClass', null!, [], [], null!, []))).toEqual([
|
||||
'class SomeClass {', '}'
|
||||
].join('\n'));
|
||||
expect(emitStmt(new o.ClassStmt('SomeClass', null!, [], [], null!, [], [
|
||||
o.StmtModifier.Exported
|
||||
]))).toEqual(['export class SomeClass {', '}'].join('\n'));
|
||||
expect(emitStmt(new o.ClassStmt('SomeClass', o.variable('SomeSuperClass'), [], [], null !, [
|
||||
]))).toEqual(['class SomeClass extends SomeSuperClass {', '}'].join('\n'));
|
||||
expect(
|
||||
emitStmt(new o.ClassStmt('SomeClass', o.variable('SomeSuperClass'), [], [], null!, [])))
|
||||
.toEqual(['class SomeClass extends SomeSuperClass {', '}'].join('\n'));
|
||||
});
|
||||
|
||||
it('should support declaring constructors', () => {
|
||||
const superCall = o.SUPER_EXPR.callFn([o.variable('someParam')]).toStmt();
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null !, [], [], new o.ClassMethod(null !, [], []), [])))
|
||||
'SomeClass', null!, [], [], new o.ClassMethod(null!, [], []), [])))
|
||||
.toEqual(['class SomeClass {', ' constructor() {', ' }', '}'].join('\n'));
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null !, [], [],
|
||||
new o.ClassMethod(null !, [new o.FnParam('someParam', o.INT_TYPE)], []), [])))
|
||||
'SomeClass', null!, [], [],
|
||||
new o.ClassMethod(null!, [new o.FnParam('someParam', o.INT_TYPE)], []), [])))
|
||||
.toEqual(
|
||||
['class SomeClass {', ' constructor(someParam:number) {', ' }', '}'].join('\n'));
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null !, [], [], new o.ClassMethod(null !, [], [superCall]), [])))
|
||||
'SomeClass', null!, [], [], new o.ClassMethod(null!, [], [superCall]), [])))
|
||||
.toEqual([
|
||||
'class SomeClass {', ' constructor() {', ' super(someParam);', ' }', '}'
|
||||
].join('\n'));
|
||||
expect(
|
||||
emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null !, [], [], new o.ClassMethod(null !, [], [callSomeMethod]), [])))
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null!, [], [], new o.ClassMethod(null!, [], [callSomeMethod]), [])))
|
||||
.toEqual([
|
||||
'class SomeClass {', ' constructor() {', ' this.someMethod();', ' }', '}'
|
||||
].join('\n'));
|
||||
@ -310,57 +316,56 @@ const externalModuleIdentifier = new o.ExternalReference(anotherModuleUrl, 'some
|
||||
|
||||
it('should support declaring fields', () => {
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null !, [new o.ClassField('someField')], [], null !, [])))
|
||||
'SomeClass', null!, [new o.ClassField('someField')], [], null!, [])))
|
||||
.toEqual(['class SomeClass {', ' someField:any;', '}'].join('\n'));
|
||||
expect(
|
||||
emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null !, [new o.ClassField('someField', o.INT_TYPE)], [], null !, [])))
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null!, [new o.ClassField('someField', o.INT_TYPE)], [], null!, [])))
|
||||
.toEqual(['class SomeClass {', ' someField:number;', '}'].join('\n'));
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null !,
|
||||
[new o.ClassField('someField', o.INT_TYPE, [o.StmtModifier.Private])], [],
|
||||
null !, [])))
|
||||
'SomeClass', null!,
|
||||
[new o.ClassField('someField', o.INT_TYPE, [o.StmtModifier.Private])], [], null!,
|
||||
[])))
|
||||
.toEqual(['class SomeClass {', ' /*private*/ someField:number;', '}'].join('\n'));
|
||||
});
|
||||
|
||||
it('should support declaring getters', () => {
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null !, [], [new o.ClassGetter('someGetter', [])], null !, [])))
|
||||
'SomeClass', null!, [], [new o.ClassGetter('someGetter', [])], null!, [])))
|
||||
.toEqual(['class SomeClass {', ' get someGetter():any {', ' }', '}'].join('\n'));
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null !, [], [new o.ClassGetter('someGetter', [], o.INT_TYPE)],
|
||||
null !, [])))
|
||||
'SomeClass', null!, [], [new o.ClassGetter('someGetter', [], o.INT_TYPE)], null!,
|
||||
[])))
|
||||
.toEqual(['class SomeClass {', ' get someGetter():number {', ' }', '}'].join('\n'));
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null !, [], [new o.ClassGetter('someGetter', [callSomeMethod])],
|
||||
null !, [])))
|
||||
'SomeClass', null!, [], [new o.ClassGetter('someGetter', [callSomeMethod])],
|
||||
null!, [])))
|
||||
.toEqual([
|
||||
'class SomeClass {', ' get someGetter():any {', ' this.someMethod();', ' }', '}'
|
||||
].join('\n'));
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null !, [],
|
||||
[new o.ClassGetter('someGetter', [], null !, [o.StmtModifier.Private])], null !,
|
||||
[])))
|
||||
expect(
|
||||
emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null!, [],
|
||||
[new o.ClassGetter('someGetter', [], null!, [o.StmtModifier.Private])], null!, [])))
|
||||
.toEqual(
|
||||
['class SomeClass {', ' private get someGetter():any {', ' }', '}'].join('\n'));
|
||||
});
|
||||
|
||||
it('should support methods', () => {
|
||||
expect(emitStmt(new o.ClassStmt('SomeClass', null !, [], [], null !, [
|
||||
expect(emitStmt(new o.ClassStmt('SomeClass', null!, [], [], null!, [
|
||||
new o.ClassMethod('someMethod', [], [])
|
||||
]))).toEqual(['class SomeClass {', ' someMethod():void {', ' }', '}'].join('\n'));
|
||||
expect(emitStmt(new o.ClassStmt('SomeClass', null !, [], [], null !, [
|
||||
expect(emitStmt(new o.ClassStmt('SomeClass', null!, [], [], null!, [
|
||||
new o.ClassMethod('someMethod', [], [], o.INT_TYPE)
|
||||
]))).toEqual(['class SomeClass {', ' someMethod():number {', ' }', '}'].join('\n'));
|
||||
expect(
|
||||
emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null !, [], [], null !,
|
||||
'SomeClass', null!, [], [], null!,
|
||||
[new o.ClassMethod('someMethod', [new o.FnParam('someParam', o.INT_TYPE)], [])])))
|
||||
.toEqual([
|
||||
'class SomeClass {', ' someMethod(someParam:number):void {', ' }', '}'
|
||||
].join('\n'));
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null !, [], [], null !,
|
||||
'SomeClass', null!, [], [], null!,
|
||||
[new o.ClassMethod('someMethod', [], [callSomeMethod])])))
|
||||
.toEqual([
|
||||
'class SomeClass {', ' someMethod():void {', ' this.someMethod();', ' }', '}'
|
||||
@ -412,7 +417,7 @@ const externalModuleIdentifier = new o.ExternalReference(anotherModuleUrl, 'some
|
||||
|
||||
it('should support combined types', () => {
|
||||
const writeVarExpr = o.variable('a').set(o.NULL_EXPR);
|
||||
expect(emitStmt(writeVarExpr.toDeclStmt(new o.ArrayType(null !))))
|
||||
expect(emitStmt(writeVarExpr.toDeclStmt(new o.ArrayType(null!))))
|
||||
.toEqual('var a:any[] = (null as any);');
|
||||
expect(emitStmt(writeVarExpr.toDeclStmt(new o.ArrayType(o.INT_TYPE))))
|
||||
.toEqual('var a:number[] = (null as any);');
|
||||
|
Reference in New Issue
Block a user