Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updates towards noImplicitAny #148

Merged
merged 2 commits into from
Oct 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"rollup": "^0.41.6",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-sourcemaps": "^0.4.2",
"rollup-plugin-typescript2": "^0.17.0",
"semver": "^5.3.0",
"simple-dom": "^1.2.0",
"simple-html-tokenizer": "^0.5.3",
Expand All @@ -66,4 +67,4 @@
"deprecation": ":warning: Deprecation"
}
}
}
}
20 changes: 16 additions & 4 deletions packages/@glimmer/app-compiler/src/bundle-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ import { mainTemplate } from '@glimmer/application';
import { CompilableProgram } from '@glimmer/opcode-compiler';
import { Opaque } from '@glimmer/util';
import { AppCompilerDelegateOptions } from '@glimmer/compiler-delegates';
import { TempDir } from 'broccoli-test-helper';

// https://github.com/joliss/node-walk-sync/blob/984a2d6adf9facc1531fb325852f475eb260781d/index.d.ts
export class WalkSyncEntry {
relativePath: string;
basePath: string;
fullPath: string;
mode: number;
size: number;
mtime: Date;
isDirectory: Function;
}

export type CompilerMode = 'module-unification';

Expand All @@ -29,7 +41,7 @@ export default class GlimmerBundleCompiler extends Plugin {
outputPath: string;
compiler: BundleCompiler<Opaque>;
private delegate: AppCompilerDelegate<Opaque>;
constructor(inputNode, options: GlimmerBundleCompilerOptions) {
constructor(inputNode: TempDir|string, options: GlimmerBundleCompilerOptions) {
super([inputNode], options);
this.options = this.defaultOptions(options);
}
Expand All @@ -47,12 +59,12 @@ export default class GlimmerBundleCompiler extends Plugin {
}, options);
}

listEntries() {
listEntries(): WalkSyncEntry[] {
let [srcPath] = this.inputPaths;
return walkSync.entries(srcPath);
}

_readFile(file) {
_readFile(file: string) {
return readFileSync(join(this.inputPaths[0], file), 'UTF-8');
}

Expand Down Expand Up @@ -88,7 +100,7 @@ export default class GlimmerBundleCompiler extends Plugin {

let [projectPath] = this.inputPaths;

this.listEntries().forEach(entry => {
this.listEntries().forEach((entry: WalkSyncEntry) => {
let { relativePath } = entry;
if (entry.isDirectory()) {
mkdirSync(join(outputPath, relativePath));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { GlimmerBundleCompiler } from '@glimmer/app-compiler';
import { createTempDir, buildOutput } from 'broccoli-test-helper';
import { createTempDir, buildOutput, TempDir, Tree } from 'broccoli-test-helper';

const { module, test } = QUnit;

module('Broccol Glimmer Bundle Compiler', function(hooks) {
let input = null;
let input:TempDir = null;

hooks.beforeEach(() => createTempDir().then(tempDir => (input = tempDir)));

Expand Down Expand Up @@ -53,7 +53,7 @@ module('Broccol Glimmer Bundle Compiler', function(hooks) {
});

let output = await buildOutput(compiler);
let files = output.read();
let files: Tree = output.read();

assert.deepEqual(Object.keys(files).sort(), ['src', 'package.json', 'templates.gbx', 'data-segment.js'].sort());
assert.deepEqual(Object.keys(files['src']).sort(), ['ui'].sort());
Expand Down
6 changes: 4 additions & 2 deletions packages/@glimmer/application-test-helpers/src/app-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { BundleCompiler, CompilerDelegate as ICompilerDelegate } from '@glimmer/
import { buildAction, mainTemplate } from '@glimmer/application';
import { CompilableProgram } from '@glimmer/opcode-compiler';
import { Cursor } from '@glimmer/runtime';
import { Metadata } from '../../application/src/loaders/bytecode/loader';

import didRender from './did-render';

Expand Down Expand Up @@ -119,9 +120,10 @@ export class AppBuilder<T extends TestApplication> {
let { heap, pool, table } = compiler.compile();

let resolverTable: Opaque[] = [];
let meta = {};

table.vmHandleByModuleLocator.forEach((vmHandle, locator) => {
let meta: Dict<Metadata> = {};

table.vmHandleByModuleLocator.forEach((vmHandle , locator) => {
let handle = table.byModuleLocator.get(locator);
let template = compiler.compilableTemplates.get(locator);

Expand Down
9 changes: 7 additions & 2 deletions packages/@glimmer/application-test-helpers/src/render-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,20 @@ export class RenderTest {
}

function setTestingDescriptor(descriptor: PropertyDescriptor): void {
let testFunction = descriptor.value as Function;
let testFunction:TestFunction = descriptor.value as TestFunction;
descriptor.enumerable = true;
testFunction['isTest'] = true;
}

export interface TestMeta {
[key: string]: any;
debug?: boolean;
}

export interface TestFunction {
[key: string]: boolean;
}

export function test(meta: TestMeta): MethodDecorator;
export function test(
_target: Object | TestMeta,
Expand All @@ -55,7 +60,7 @@ export function test(...args: any[]) {
if (args.length === 1) {
let meta: TestMeta = args[0];
return (_target: Object, _name: string, descriptor: PropertyDescriptor) => {
let testFunction = descriptor.value as Function;
let testFunction: TestFunction = descriptor.value as TestFunction;
Object.keys(meta).forEach(key => (testFunction[key] = meta[key]));
setTestingDescriptor(descriptor);
};
Expand Down
8 changes: 6 additions & 2 deletions packages/@glimmer/application/src/dynamic-scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ import {
PathReference
} from '@glimmer/reference';

interface Bucket {
[key: string]: PathReference<Opaque>;
}

export default class DynamicScope implements GlimmerDynamicScope {
private bucket;
private bucket: Bucket;

constructor(bucket=null) {
constructor(bucket: Bucket = null) {
if (bucket) {
this.bucket = assign({}, bucket);
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/@glimmer/application/src/helpers/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function buildAction(vm: VM, _args: Arguments) {
throwNoActionError(actionFunc, args.positional.at(0));
}

return new UpdatableReference(function action(...invokedArgs) {
return new UpdatableReference(function action(...invokedArgs: any[]) {
let curriedArgs = args.positional.value();
// Consume the action function that was already captured above.
curriedArgs.shift();
Expand Down
2 changes: 1 addition & 1 deletion packages/@glimmer/application/src/helpers/user-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {

export type UserHelper = (args: ReadonlyArray<Opaque>, named: Dict<Opaque>) => any;

export default function buildUserHelper(helperFunc): GlimmerHelper {
export default function buildUserHelper(helperFunc: UserHelper): GlimmerHelper {
return (_vm: VM, args: Arguments) => new HelperReference(helperFunc, args);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/@glimmer/application/src/iterable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ export default class Iterable implements AbstractIterable<Opaque, Opaque, Iterat
} else if (iterable === undefined || iterable === null) {
return EMPTY_ITERATOR;
} else if (iterable.forEach !== undefined) {
let array = [];
iterable.forEach(function(item) {
let array: any[] = [];
iterable.forEach(function(item: any) {
array.push(item);
});
return array.length > 0 ? new ArrayIterator(array, keyFor) : EMPTY_ITERATOR;
Expand Down
8 changes: 5 additions & 3 deletions packages/@glimmer/application/src/loaders/bytecode/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ export interface SerializedHeap {
}

export interface Metadata {
[key: string]: number | ProgramSymbolTable;

/** VM handle */
v: number;
v?: number;
/** Handle */
h: number;
h?: number;

table: ProgramSymbolTable;
table?: ProgramSymbolTable;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/@glimmer/application/test/browser/action-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test('can curry arguments to actions', async function(assert) {
helloWorldComponent = this;
}

userDidClick(msg1, msg2, event) {
userDidClick(msg1: string, msg2: string, event: Event) {
passedMsg1 = msg1;
passedMsg2 = msg2;
passedEvent = event;
Expand Down Expand Up @@ -67,7 +67,7 @@ test('actions can be passed and invoked with additional arguments', async functi
type: 'click'
};
let parentComponent: ParentComponent;
let passed = [];
let passed: any[] = [];

class ParentComponent extends Component {
name = "world";
Expand All @@ -77,7 +77,7 @@ test('actions can be passed and invoked with additional arguments', async functi
parentComponent = this;
}

userDidClick(a1, a2, a3, a4, a5, a6, evt) {
userDidClick(a1: number, a2: number, a3: number, a4: number, a5: number, a6: number, evt: Event) {
passed = [a1, a2, a3, a4, a5, a6, evt];
assert.strictEqual(this, parentComponent, 'function context is preserved');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ const { module, test } = QUnit;

module('[@glimmer/application] Owner interface');

interface FooBarClass {
[key: string]: any;
}

test('#identify - uses a resolver to convert a relative specifier to an absolute specifier', function(assert) {
assert.expect(2);

Expand Down Expand Up @@ -120,7 +124,7 @@ test('#lookup - returns an instance created by the factory', function(assert) {
let instance = { foo: 'bar' };

class FooBar {
static create(injections) {
static create(injections: Object) {
assert.ok(true, 'Factory#create invoked');
assert.strictEqual(getOwner(injections), app, 'owner is included in injections');
return instance;
Expand Down Expand Up @@ -248,11 +252,11 @@ test('#lookup - uses the resolver to locate a registration', function(assert) {
test('#lookup - injects references registered by name', function(assert) {
assert.expect(5);

let instance = { foo: 'bar' };
let instance: FooBarClass = { foo: 'bar' };
let router = { name: 'router' };

class FooBar {
static create(injections) {
static create(injections: FooBarClass) {
assert.ok(true, 'FooBarFactory#create invoked');
assert.strictEqual(injections['router'], router, 'expected injections passed to factory');
instance['router'] = injections['router'];
Expand Down Expand Up @@ -286,11 +290,11 @@ test('#lookup - injects references registered by name', function(assert) {
test('#lookup - injects references registered by type', function(assert) {
assert.expect(5);

let instance = { foo: 'bar' };
let instance: FooBarClass = { foo: 'bar' };
let router = { name: 'router' };

class FooBar {
static create(injections) {
static create(injections: FooBarClass) {
assert.ok(true, 'FooBarFactory#create invoked');
assert.strictEqual(injections['router'], router, 'expected injections passed to factory');
instance['router'] = injections['router'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ test('can render a custom helper that takes args', async function(assert) {
}

let app = await buildApp()
.helper('greeting', (params) => `Hello ${params[0]} ${params[1]}!`)
.helper('greeting', (params: string[]) => `Hello ${params[0]} ${params[1]}!`)
.template('Main', '<div>{{greeting firstName lastName}}</div>')
.component('Main', MainComponent)
.boot();
Expand Down
20 changes: 10 additions & 10 deletions packages/@glimmer/application/test/browser/render-component-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Component, { tracked } from '@glimmer/component';
import '../helpers/async';

class RenderComponentTest extends RenderTest {
@test async "renders a component"(assert) {
@test async "renders a component"(assert: Assert) {
assert.expect(1);

let containerElement = document.createElement('div');
Expand All @@ -22,7 +22,7 @@ class RenderComponentTest extends RenderTest {
assert.equal(containerElement.innerHTML, '<h1>A B Hello Glimmer!</h1>');
}

@test async 'renders a component without affecting existing content'(assert) {
@test async 'renders a component without affecting existing content'(assert: Assert) {
assert.expect(2);

let containerElement = document.createElement('div');
Expand All @@ -45,7 +45,7 @@ class RenderComponentTest extends RenderTest {
assert.equal(containerElement.innerHTML, '<p>foo</p>bar<h1>Hello Glimmer!</h1>');
}

@test async 'renders a component before a given sibling'(assert) {
@test async 'renders a component before a given sibling'(assert: Assert) {
assert.expect(2);

let containerElement = document.createElement('div');
Expand All @@ -68,7 +68,7 @@ class RenderComponentTest extends RenderTest {
assert.equal(containerElement.innerHTML, '<p></p><h1>Hello Glimmer!</h1><aside></aside>');
}

@test async 'renders multiple components in different places'(assert) {
@test async 'renders multiple components in different places'(assert: Assert) {
assert.expect(2);

let firstContainerElement = document.createElement('div');
Expand All @@ -88,7 +88,7 @@ class RenderComponentTest extends RenderTest {
assert.equal(secondContainerElement.innerHTML, '<h1>Hello Robbie!</h1>');
}

@test async 'renders multiple components in the same container'(assert) {
@test async 'renders multiple components in the same container'(assert: Assert) {
assert.expect(1);

let containerElement = document.createElement('div');
Expand All @@ -106,7 +106,7 @@ class RenderComponentTest extends RenderTest {
assert.equal(containerElement.innerHTML, '<h1>Hello Glimmer!</h1><h1>Hello Robbie!</h1>');
}

@test async 'renders multiple components in the same container in particular places'(assert) {
@test async 'renders multiple components in the same container in particular places'(assert: Assert) {
assert.expect(2);

let containerElement = document.createElement('div');
Expand All @@ -129,7 +129,7 @@ class RenderComponentTest extends RenderTest {
assert.equal(containerElement.innerHTML, '<h1>Hello Robbie!</h1><aside></aside><h1>Hello Glimmer!</h1>');
}

@test async 'user helpers are not volatile'(assert) {
@test async 'user helpers are not volatile'(assert: Assert) {
assert.expect(6);

let containerElement = document.createElement('div');
Expand All @@ -141,7 +141,7 @@ class RenderComponentTest extends RenderTest {

class HelloWorld extends Component {
@tracked a = 'a';
constructor(options) {
constructor(options: any) {
super(options);
component = this;
}
Expand All @@ -150,7 +150,7 @@ class RenderComponentTest extends RenderTest {
let count = 0;

let app = await this.app
.helper('woot', (params) => {
.helper('woot', (params: any) => {
count++;
return params[0];
})
Expand Down Expand Up @@ -186,7 +186,7 @@ class RenderComponentTest extends RenderTest {
}

@test({ debug: true })
async 'throws an exception if an invoked component is not found'(assert) {
async 'throws an exception if an invoked component is not found'(assert: Assert) {
assert.expect(1);

let containerElement = document.createElement('div');
Expand Down