From b402cbf4258bbb86af6ec75bb81fb2e35401eeb4 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Tue, 29 Aug 2017 11:08:26 -0400 Subject: [PATCH 01/24] Add broccoli-typescript-compiler. --- package.json | 1 + yarn.lock | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 0a8b2356e7b..c4c36bde85e 100644 --- a/package.json +++ b/package.json @@ -89,6 +89,7 @@ "broccoli-lint-eslint": "^3.2.1", "broccoli-rollup": "^1.2.0", "broccoli-string-replace": "^0.1.2", + "broccoli-typescript-compiler": "^2.0.1", "broccoli-uglify-js": "^0.2.0", "broccoli-uglify-sourcemap": "^1.5.2", "chalk": "^1.1.1", diff --git a/yarn.lock b/yarn.lock index 489f047a870..66092087cfc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -267,6 +267,10 @@ arr-flatten@^1.0.1: version "1.1.0" resolved "https://registry.yarnpkg.com/arr-flatten/-/arr-flatten-1.1.0.tgz#36048bbff4e7b47e136644316c99669ea5ae91f1" +array-binsearch@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/array-binsearch/-/array-binsearch-1.0.1.tgz#35586dca04ca9ab259c4c4708435acd1babb08ad" + array-equal@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/array-equal/-/array-equal-1.0.0.tgz#8c2a5ef2472fd9ea742b04c77a75093ba2757c93" @@ -1313,6 +1317,20 @@ broccoli-string-replace@^0.1.2: broccoli-persistent-filter "^1.1.5" minimatch "^3.0.3" +broccoli-typescript-compiler@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/broccoli-typescript-compiler/-/broccoli-typescript-compiler-2.0.1.tgz#8d30df28f051a425b1919611919c033d0789bd03" + dependencies: + array-binsearch "^1.0.1" + broccoli-funnel "^1.2.0" + broccoli-merge-trees "^2.0.0" + broccoli-plugin "^1.2.1" + fs-tree-diff "^0.5.2" + heimdalljs "0.3.3" + md5-hex "^2.0.0" + typescript "~2.4.2" + walk-sync "^0.3.2" + broccoli-uglify-js@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/broccoli-uglify-js/-/broccoli-uglify-js-0.2.0.tgz#3701901c8eafbb48d58936a45a8592749003a1c8" @@ -3281,6 +3299,12 @@ heimdalljs-logger@^0.1.7: debug "^2.2.0" heimdalljs "^0.2.0" +heimdalljs@0.3.3: + version "0.3.3" + resolved "https://registry.yarnpkg.com/heimdalljs/-/heimdalljs-0.3.3.tgz#e92d2c6f77fd46d5bf50b610d28ad31755054d0b" + dependencies: + rsvp "~3.2.1" + heimdalljs@^0.2.0, heimdalljs@^0.2.1, heimdalljs@^0.2.3: version "0.2.5" resolved "https://registry.yarnpkg.com/heimdalljs/-/heimdalljs-0.2.5.tgz#6aa54308eee793b642cff9cf94781445f37730ac" @@ -6005,6 +6029,10 @@ typedarray@^0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" +typescript@~2.4.2: + version "2.4.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.4.2.tgz#f8395f85d459276067c988aa41837a8f82870844" + uc.micro@^1.0.0, uc.micro@^1.0.1, uc.micro@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/uc.micro/-/uc.micro-1.0.3.tgz#7ed50d5e0f9a9fb0a573379259f2a77458d50192" @@ -6185,7 +6213,7 @@ walk-sync@^0.2.0, walk-sync@^0.2.5, walk-sync@^0.2.7: ensure-posix-path "^1.0.0" matcher-collection "^1.0.0" -walk-sync@^0.3.0, walk-sync@^0.3.1: +walk-sync@^0.3.0, walk-sync@^0.3.1, walk-sync@^0.3.2: version "0.3.2" resolved "https://registry.yarnpkg.com/walk-sync/-/walk-sync-0.3.2.tgz#4827280afc42d0e035367c4a4e31eeac0d136f75" dependencies: From 039dee9d9478ceaeab44e5daa7efb6a99f088202 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Tue, 29 Aug 2017 13:31:14 -0400 Subject: [PATCH 02/24] Enable typescript for ember-glimmer. --- .gitignore | 1 + broccoli/glimmer-template-compiler.js | 4 +-- broccoli/packages.js | 21 ++++++++++--- ember-cli-build.js | 12 +++++--- package.json | 2 ++ packages/ember-glimmer/{lib => }/index.js | 34 ++++++++++----------- tsconfig.json | 37 +++++++++++++++++++++++ yarn.lock | 12 ++++++++ 8 files changed, 96 insertions(+), 27 deletions(-) rename packages/ember-glimmer/{lib => }/index.js (89%) create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore index 37c9f7bd638..243a726cdaf 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,4 @@ publish_to_bower/ bower_components/ npm-debug.log .ember-cli +DEBUG/ diff --git a/broccoli/glimmer-template-compiler.js b/broccoli/glimmer-template-compiler.js index ecf9f2855f9..85f46f8e76f 100644 --- a/broccoli/glimmer-template-compiler.js +++ b/broccoli/glimmer-template-compiler.js @@ -21,7 +21,7 @@ function GlimmerTemplatePrecompiler (inputTree, options) { } GlimmerTemplatePrecompiler.prototype.extensions = ['hbs']; -GlimmerTemplatePrecompiler.prototype.targetExtension = 'js'; +GlimmerTemplatePrecompiler.prototype.targetExtension = 'ts'; GlimmerTemplatePrecompiler.prototype.baseDir = function() { return __dirname; @@ -35,4 +35,4 @@ GlimmerTemplatePrecompiler.prototype.processString = function(content, relativeP `; }; -module.exports = GlimmerTemplatePrecompiler; \ No newline at end of file +module.exports = GlimmerTemplatePrecompiler; diff --git a/broccoli/packages.js b/broccoli/packages.js index 62429afb86b..ad8bf317185 100644 --- a/broccoli/packages.js +++ b/broccoli/packages.js @@ -4,6 +4,9 @@ const { readFileSync } = require('fs'); const path = require('path'); const Rollup = require('broccoli-rollup'); const Funnel = require('broccoli-funnel'); +const filterTypeScript = require('broccoli-typescript-compiler').filterTypeScript; +const TypeScriptPlugin = require('broccoli-typescript-compiler').TypeScriptPlugin; +const BroccoliDebug = require('broccoli-debug'); const findLib = require('./find-lib'); const funnelLib = require('./funnel-lib'); const { VERSION } = require('./version'); @@ -15,6 +18,8 @@ const VERSION_PLACEHOLDER = /VERSION_STRING_PLACEHOLDER/g; const { stripIndent } = require('common-tags'); const toES5 = require('./to-es5'); +const debugTree = BroccoliDebug.buildDebugCallback('ember-source'); + module.exports.routerES = function _routerES() { return new Rollup(findLib('router_js'), { rollup: { @@ -57,16 +62,24 @@ module.exports.qunit = function _qunit() { } module.exports.emberGlimmerES = function _emberGlimmerES() { - let pkg = new Funnel('packages/ember-glimmer/lib', { - include: ['**/*.js', '**/*.hbs'], - destDir: 'ember-glimmer' + let input = new Funnel('packages/ember-glimmer', { + include: ['lib/**/*', 'index.*'], + destDir: 'packages/ember-glimmer' }); - return new GlimmerTemplatePrecompiler(pkg, { + let debuggedInput = debugTree(input, 'ember-glimmer:input'); + + let compiledTemplatesAndTypescript = new GlimmerTemplatePrecompiler(debuggedInput, { persist: true, glimmer: require('@glimmer/compiler'), annotation: 'ember-glimmer es' }); + + let debuggedCompiledTemplatesAndTypeScript = debugTree(compiledTemplatesAndTypescript, 'ember-glimmer:templates-output'); + + let typescriptCompiled = new TypeScriptPlugin(debuggedCompiledTemplatesAndTypeScript); + + return debugTree(typescriptCompiled, 'ember-glimmer:output'); } module.exports.handlebarsES = function _handlebars() { diff --git a/ember-cli-build.js b/ember-cli-build.js index 454ce8f8d45..02d58b49ded 100644 --- a/ember-cli-build.js +++ b/ember-cli-build.js @@ -1,6 +1,12 @@ 'use strict'; /* eslint-env node */ +// To create fast production builds (without ES3 support, minification, derequire, or JSHint) +// run the following: +// +// DISABLE_ES3=true DISABLE_JSCS=true DISABLE_JSHINT=true DISABLE_MIN=true DISABLE_DEREQUIRE=true ember serve --environment=production + +const UnwatchedDir = require('broccoli-source').UnwatchedDir; const MergeTrees = require('broccoli-merge-trees'); const Funnel = require('broccoli-funnel'); const babelHelpers = require('./broccoli/babel-helpers'); @@ -89,8 +95,7 @@ module.exports = function(options) { let backburner = toES5(backburnerES()); // Linting - let emberTestsLinted = emberTests.map(lint); - let emberLinted = emberCoreES6.map(lint); + let linting = lint(new UnwatchedDir('packages')); // ES5 let dependenciesES5 = dependenciesES6().map(toES5); @@ -101,8 +106,7 @@ module.exports = function(options) { // Bundling let emberTestsBundle = new MergeTrees([ ...emberTestsES5, - ...emberTestsLinted, - ...emberLinted, + linting, loader, nodeModule, license, diff --git a/package.json b/package.json index c4c36bde85e..433ebc6a0a1 100644 --- a/package.json +++ b/package.json @@ -85,9 +85,11 @@ "backburner.js": "^1.2.2", "broccoli-babel-transpiler": "next", "broccoli-concat": "^3.2.2", + "broccoli-debug": "^0.6.3", "broccoli-file-creator": "^1.1.1", "broccoli-lint-eslint": "^3.2.1", "broccoli-rollup": "^1.2.0", + "broccoli-source": "^1.1.0", "broccoli-string-replace": "^0.1.2", "broccoli-typescript-compiler": "^2.0.1", "broccoli-uglify-js": "^0.2.0", diff --git a/packages/ember-glimmer/lib/index.js b/packages/ember-glimmer/index.js similarity index 89% rename from packages/ember-glimmer/lib/index.js rename to packages/ember-glimmer/index.js index 4622e8d06dd..43f70a8e72b 100644 --- a/packages/ember-glimmer/lib/index.js +++ b/packages/ember-glimmer/index.js @@ -259,37 +259,37 @@ @public */ -export { INVOKE } from './helpers/action'; -export { default as RootTemplate } from './templates/root'; -export { default as template } from './template'; -export { default as Checkbox } from './components/checkbox'; -export { default as TextField } from './components/text_field'; -export { default as TextArea } from './components/text_area'; -export { default as LinkComponent } from './components/link-to'; -export { default as Component } from './component'; -export { default as Helper, helper } from './helper'; -export { default as Environment } from './environment'; +export { INVOKE } from './lib/helpers/action'; +export { default as RootTemplate } from './lib/templates/root'; +export { default as template } from './lib/template'; +export { default as Checkbox } from './lib/components/checkbox'; +export { default as TextField } from './lib/components/text_field'; +export { default as TextArea } from './lib/components/text_area'; +export { default as LinkComponent } from './lib/components/link-to'; +export { default as Component } from './lib/component'; +export { default as Helper, helper } from './lib/helper'; +export { default as Environment } from './lib/environment'; export { SafeString, escapeExpression, htmlSafe, isHTMLSafe, getSafeString as _getSafeString -} from './utils/string'; +} from './lib/utils/string'; export { Renderer, InertRenderer, InteractiveRenderer, _resetRenderers -} from './renderer'; +} from './lib/renderer'; export { getTemplate, setTemplate, hasTemplate, getTemplates, setTemplates -} from './template_registry'; -export { setupEngineRegistry, setupApplicationRegistry } from './setup-registry'; -export { DOMChanges, NodeDOMTreeConstruction, DOMTreeConstruction } from './dom'; -export { registerMacros as _registerMacros, experimentalMacros as _experimentalMacros } from './syntax'; -export { default as AbstractComponentManager } from './component-managers/abstract'; +} from './lib/template_registry'; +export { setupEngineRegistry, setupApplicationRegistry } from './lib/setup-registry'; +export { DOMChanges, NodeDOMTreeConstruction, DOMTreeConstruction } from './lib/dom'; +export { registerMacros as _registerMacros, experimentalMacros as _experimentalMacros } from './lib/syntax'; +export { default as AbstractComponentManager } from './lib/component-managers/abstract'; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000000..0618ed0bafb --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,37 @@ +{ + "compilerOptions": { + // Compilation Configuration + "target": "es5", + "module": "es2015", + "inlineSources": true, + "inlineSourceMap": true, + "outDir": "dist", + "baseUrl" : "packages", + "rootDir": "packages", + + // Environment Configuration + "experimentalDecorators": true, + "moduleResolution": "node", + + // Enhance Strictness + "noImplicitAny": true, + "suppressImplicitAnyIndexErrors": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "allowUnreachableCode": false, + "strictNullChecks": true, + "noImplicitReturns": true, + "noImplicitThis": true, + + "newLine": "LF", + "noEmit": false, + "allowJs": true + }, + "exclude": [ + "dist", + "demos", + "tmp", + "node_modules", + ".vscode" + ] +} diff --git a/yarn.lock b/yarn.lock index 66092087cfc..7a3b48e852e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1128,6 +1128,18 @@ broccoli-debug@^0.6.1: symlink-or-copy "^1.1.8" tree-sync "^1.2.2" +broccoli-debug@^0.6.3: + version "0.6.3" + resolved "https://registry.yarnpkg.com/broccoli-debug/-/broccoli-debug-0.6.3.tgz#1f33bb0eacb5db81366f0492524c82b1217eb578" + dependencies: + broccoli-plugin "^1.2.1" + fs-tree-diff "^0.5.2" + heimdalljs "^0.2.1" + heimdalljs-logger "^0.1.7" + minimatch "^3.0.3" + symlink-or-copy "^1.1.8" + tree-sync "^1.2.2" + broccoli-file-creator@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/broccoli-file-creator/-/broccoli-file-creator-1.1.1.tgz#1b35b67d215abdfadd8d49eeb69493c39e6c3450" From 988a06b6805c531ea1d0a377aff9206a9beb96f4 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Tue, 29 Aug 2017 16:22:51 -0700 Subject: [PATCH 03/24] Useful increment --- bin/yarn-link-glimmer.js | 11 +++----- packages/ember-debug/lib/ember-env-flags.d.ts | 3 +++ packages/ember-debug/lib/index.d.ts | 1 + tsconfig.json | 25 +++++++++++++------ 4 files changed, 25 insertions(+), 15 deletions(-) create mode 100644 packages/ember-debug/lib/ember-env-flags.d.ts create mode 100644 packages/ember-debug/lib/index.d.ts diff --git a/bin/yarn-link-glimmer.js b/bin/yarn-link-glimmer.js index 18bfbf46be8..557269bcdff 100755 --- a/bin/yarn-link-glimmer.js +++ b/bin/yarn-link-glimmer.js @@ -5,14 +5,11 @@ const glimmerDeps = []; addGlimmerPackageDeps(require("../package"), true); -glimmerDeps.forEach(dep => { - console.log(dep); - child_process.execSync(`yarn link "${dep}"`); -}); - -function addGlimmerDep(glimmerDep) { +function linkGlimmerDep(glimmerDep) { if (glimmerDeps.indexOf(glimmerDep) === -1) { glimmerDeps.push(glimmerDep); + console.log(glimmerDep); + child_process.execSync(`yarn link "${glimmerDep}"`); addGlimmerPackageDeps(require(`${glimmerDep}/package`), false); } } @@ -21,7 +18,7 @@ function addGlimmerDeps(dependencies) { if (!dependencies) return; Object.keys(dependencies).forEach(dep => { if (dep.lastIndexOf("@glimmer", 0) === 0) { - addGlimmerDep(dep); + linkGlimmerDep(dep); } }); } diff --git a/packages/ember-debug/lib/ember-env-flags.d.ts b/packages/ember-debug/lib/ember-env-flags.d.ts new file mode 100644 index 00000000000..0f0a26704c6 --- /dev/null +++ b/packages/ember-debug/lib/ember-env-flags.d.ts @@ -0,0 +1,3 @@ +declare module 'ember-env-flags' { + export const DEBUG: boolean; +} diff --git a/packages/ember-debug/lib/index.d.ts b/packages/ember-debug/lib/index.d.ts new file mode 100644 index 00000000000..48622e4b3e5 --- /dev/null +++ b/packages/ember-debug/lib/index.d.ts @@ -0,0 +1 @@ +export function assert(message: string, test: boolean): void; diff --git a/tsconfig.json b/tsconfig.json index 0618ed0bafb..eca63ca992e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,19 +14,28 @@ "moduleResolution": "node", // Enhance Strictness - "noImplicitAny": true, - "suppressImplicitAnyIndexErrors": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "allowUnreachableCode": false, + // "noImplicitAny": true, + // "suppressImplicitAnyIndexErrors": true, + // "noUnusedLocals": true, + // "noUnusedParameters": true, + // "allowUnreachableCode": false, "strictNullChecks": true, - "noImplicitReturns": true, - "noImplicitThis": true, + // "noImplicitReturns": true, + // "noImplicitThis": true, "newLine": "LF", "noEmit": false, - "allowJs": true + "allowJs": true, + + "paths": { + "*": ["*/lib"] + } }, + + "include": [ + "packages/**/*.ts" + ], + "exclude": [ "dist", "demos", From d23a1ccbe9f50f304805fcb4cd6ffb0d3b66b012 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Tue, 29 Aug 2017 16:54:53 -0700 Subject: [PATCH 04/24] Remove .d.ts files --- packages/ember-debug/lib/ember-env-flags.d.ts | 3 --- packages/ember-debug/lib/index.d.ts | 1 - 2 files changed, 4 deletions(-) delete mode 100644 packages/ember-debug/lib/ember-env-flags.d.ts delete mode 100644 packages/ember-debug/lib/index.d.ts diff --git a/packages/ember-debug/lib/ember-env-flags.d.ts b/packages/ember-debug/lib/ember-env-flags.d.ts deleted file mode 100644 index 0f0a26704c6..00000000000 --- a/packages/ember-debug/lib/ember-env-flags.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -declare module 'ember-env-flags' { - export const DEBUG: boolean; -} diff --git a/packages/ember-debug/lib/index.d.ts b/packages/ember-debug/lib/index.d.ts deleted file mode 100644 index 48622e4b3e5..00000000000 --- a/packages/ember-debug/lib/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export function assert(message: string, test: boolean): void; From 236ee8ad01875540b6026f62f07825ab5a97b4a3 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Tue, 29 Aug 2017 17:59:15 -0700 Subject: [PATCH 05/24] Working TS --- broccoli/packages.js | 9 ++--- ember-cli-build.js | 5 ++- .../ember-glimmer/{index.js => lib/index.ts} | 34 +++++++++---------- tsconfig.json | 5 +-- 4 files changed, 29 insertions(+), 24 deletions(-) rename packages/ember-glimmer/{index.js => lib/index.ts} (89%) diff --git a/broccoli/packages.js b/broccoli/packages.js index ad8bf317185..4cc6298de0e 100644 --- a/broccoli/packages.js +++ b/broccoli/packages.js @@ -62,8 +62,7 @@ module.exports.qunit = function _qunit() { } module.exports.emberGlimmerES = function _emberGlimmerES() { - let input = new Funnel('packages/ember-glimmer', { - include: ['lib/**/*', 'index.*'], + let input = new Funnel('packages/ember-glimmer/lib', { destDir: 'packages/ember-glimmer' }); @@ -77,7 +76,9 @@ module.exports.emberGlimmerES = function _emberGlimmerES() { let debuggedCompiledTemplatesAndTypeScript = debugTree(compiledTemplatesAndTypescript, 'ember-glimmer:templates-output'); - let typescriptCompiled = new TypeScriptPlugin(debuggedCompiledTemplatesAndTypeScript); + let typescriptCompiled = new TypeScriptPlugin(debuggedCompiledTemplatesAndTypeScript, { + compilerOptions: { allowJs: true } + }); return debugTree(typescriptCompiled, 'ember-glimmer:output'); } @@ -187,7 +188,7 @@ module.exports.emberPkgES = function _emberPkgES(name, rollup, externs) { } return new Funnel(`packages/${name}/lib`, { - exclude: ['.gitkeep'], + exclude: ['.gitkeep', '**/*.d.ts'], destDir: name, annotation: `${name} es` }); diff --git a/ember-cli-build.js b/ember-cli-build.js index 02d58b49ded..dd95110e34d 100644 --- a/ember-cli-build.js +++ b/ember-cli-build.js @@ -95,7 +95,10 @@ module.exports = function(options) { let backburner = toES5(backburnerES()); // Linting - let linting = lint(new UnwatchedDir('packages')); + let packages = new UnwatchedDir('packages'); + let linting = lint(new Funnel(packages, { + include: ['**/*.js'] + })); // ES5 let dependenciesES5 = dependenciesES6().map(toES5); diff --git a/packages/ember-glimmer/index.js b/packages/ember-glimmer/lib/index.ts similarity index 89% rename from packages/ember-glimmer/index.js rename to packages/ember-glimmer/lib/index.ts index 43f70a8e72b..4622e8d06dd 100644 --- a/packages/ember-glimmer/index.js +++ b/packages/ember-glimmer/lib/index.ts @@ -259,37 +259,37 @@ @public */ -export { INVOKE } from './lib/helpers/action'; -export { default as RootTemplate } from './lib/templates/root'; -export { default as template } from './lib/template'; -export { default as Checkbox } from './lib/components/checkbox'; -export { default as TextField } from './lib/components/text_field'; -export { default as TextArea } from './lib/components/text_area'; -export { default as LinkComponent } from './lib/components/link-to'; -export { default as Component } from './lib/component'; -export { default as Helper, helper } from './lib/helper'; -export { default as Environment } from './lib/environment'; +export { INVOKE } from './helpers/action'; +export { default as RootTemplate } from './templates/root'; +export { default as template } from './template'; +export { default as Checkbox } from './components/checkbox'; +export { default as TextField } from './components/text_field'; +export { default as TextArea } from './components/text_area'; +export { default as LinkComponent } from './components/link-to'; +export { default as Component } from './component'; +export { default as Helper, helper } from './helper'; +export { default as Environment } from './environment'; export { SafeString, escapeExpression, htmlSafe, isHTMLSafe, getSafeString as _getSafeString -} from './lib/utils/string'; +} from './utils/string'; export { Renderer, InertRenderer, InteractiveRenderer, _resetRenderers -} from './lib/renderer'; +} from './renderer'; export { getTemplate, setTemplate, hasTemplate, getTemplates, setTemplates -} from './lib/template_registry'; -export { setupEngineRegistry, setupApplicationRegistry } from './lib/setup-registry'; -export { DOMChanges, NodeDOMTreeConstruction, DOMTreeConstruction } from './lib/dom'; -export { registerMacros as _registerMacros, experimentalMacros as _experimentalMacros } from './lib/syntax'; -export { default as AbstractComponentManager } from './lib/component-managers/abstract'; +} from './template_registry'; +export { setupEngineRegistry, setupApplicationRegistry } from './setup-registry'; +export { DOMChanges, NodeDOMTreeConstruction, DOMTreeConstruction } from './dom'; +export { registerMacros as _registerMacros, experimentalMacros as _experimentalMacros } from './syntax'; +export { default as AbstractComponentManager } from './component-managers/abstract'; diff --git a/tsconfig.json b/tsconfig.json index eca63ca992e..c151f96c030 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { // Compilation Configuration - "target": "es5", + "target": "es2015", "module": "es2015", "inlineSources": true, "inlineSourceMap": true, @@ -33,7 +33,8 @@ }, "include": [ - "packages/**/*.ts" + "packages/**/*.ts", + "packages/**/*.js" ], "exclude": [ From 26f30a5e4cdd94896e8dde3ffaa9d6f456edfc95 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Tue, 29 Aug 2017 17:59:33 -0700 Subject: [PATCH 06/24] Change some util files into TS --- packages/ember-debug/lib/index.d.ts | 1 + packages/ember-glimmer/externs.d.ts | 3 ++ packages/ember-glimmer/lib/renderer.js | 2 +- .../ember-glimmer/lib/templates/root.d.ts | 2 + .../lib/utils/{bindings.js => bindings.ts} | 38 ++++++++++--------- ...ket.js => curly-component-state-bucket.ts} | 22 ++++++++--- .../utils/{debug-stack.js => debug-stack.ts} | 9 ++--- 7 files changed, 49 insertions(+), 28 deletions(-) create mode 100644 packages/ember-debug/lib/index.d.ts create mode 100644 packages/ember-glimmer/externs.d.ts create mode 100644 packages/ember-glimmer/lib/templates/root.d.ts rename packages/ember-glimmer/lib/utils/{bindings.js => bindings.ts} (84%) rename packages/ember-glimmer/lib/utils/{curly-component-state-bucket.js => curly-component-state-bucket.ts} (56%) rename packages/ember-glimmer/lib/utils/{debug-stack.js => debug-stack.ts} (92%) diff --git a/packages/ember-debug/lib/index.d.ts b/packages/ember-debug/lib/index.d.ts new file mode 100644 index 00000000000..48622e4b3e5 --- /dev/null +++ b/packages/ember-debug/lib/index.d.ts @@ -0,0 +1 @@ +export function assert(message: string, test: boolean): void; diff --git a/packages/ember-glimmer/externs.d.ts b/packages/ember-glimmer/externs.d.ts new file mode 100644 index 00000000000..0f0a26704c6 --- /dev/null +++ b/packages/ember-glimmer/externs.d.ts @@ -0,0 +1,3 @@ +declare module 'ember-env-flags' { + export const DEBUG: boolean; +} diff --git a/packages/ember-glimmer/lib/renderer.js b/packages/ember-glimmer/lib/renderer.js index 29cf5c9b7cf..02423514a81 100644 --- a/packages/ember-glimmer/lib/renderer.js +++ b/packages/ember-glimmer/lib/renderer.js @@ -161,7 +161,7 @@ function loopEnd(current, next) { backburner.on('begin', loopBegin); backburner.on('end', loopEnd); -class Renderer { +export class Renderer { constructor(env, rootTemplate, _viewRegistry = fallbackViewRegistry, destinedForDOM = false) { this._env = env; this._rootTemplate = rootTemplate; diff --git a/packages/ember-glimmer/lib/templates/root.d.ts b/packages/ember-glimmer/lib/templates/root.d.ts new file mode 100644 index 00000000000..c800f6734c1 --- /dev/null +++ b/packages/ember-glimmer/lib/templates/root.d.ts @@ -0,0 +1,2 @@ +declare const TEMPLATE: any; +export default TEMPLATE; diff --git a/packages/ember-glimmer/lib/utils/bindings.js b/packages/ember-glimmer/lib/utils/bindings.ts similarity index 84% rename from packages/ember-glimmer/lib/utils/bindings.js rename to packages/ember-glimmer/lib/utils/bindings.ts index 98112257981..77425fe423c 100644 --- a/packages/ember-glimmer/lib/utils/bindings.js +++ b/packages/ember-glimmer/lib/utils/bindings.ts @@ -2,8 +2,11 @@ import { CachedReference, combine, map, - referenceFromParts + referenceFromParts, + Reference, + Tag } from '@glimmer/reference'; +import { Opaque, Option } from '@glimmer/interfaces'; import { Ops } from '@glimmer/wire-format'; @@ -100,22 +103,21 @@ export const AttributeBinding = { const DISPLAY_NONE = 'display: none;'; const SAFE_DISPLAY_NONE = htmlSafe(DISPLAY_NONE); -class StyleBindingReference extends CachedReference { - constructor(inner, isVisible) { +class StyleBindingReference extends CachedReference { + public tag: Tag; + constructor(private inner: Reference, private isVisible: Reference) { super(); this.tag = combine([inner.tag, isVisible.tag]); - this.inner = inner; - this.isVisible = isVisible; } - compute() { + compute(): string { let value = this.inner.value(); let isVisible = this.isVisible.value(); if (isVisible !== false) { return value; - } else if (!value && value !== 0) { + } else if (!value) { return SAFE_DISPLAY_NONE; } else { let style = value + ' ' + DISPLAY_NONE; @@ -158,8 +160,11 @@ export const ClassNameBinding = { } }; -class SimpleClassNameBindingReference extends CachedReference { - constructor(inner, path) { +class SimpleClassNameBindingReference extends CachedReference> { + public tag: Tag; + private dasherizedPath: Option; + + constructor(private inner: Reference, private path: string) { super(); this.tag = inner.tag; @@ -168,31 +173,30 @@ class SimpleClassNameBindingReference extends CachedReference { this.dasherizedPath = null; } - compute() { + compute(): Option { let value = this.inner.value(); if (value === true) { let { path, dasherizedPath } = this; return dasherizedPath || (this.dasherizedPath = StringUtils.dasherize(path)); } else if (value || value === 0) { - return value; + return String(value); } else { return null; } } } -class ColonClassNameBindingReference extends CachedReference { - constructor(inner, truthy, falsy) { +class ColonClassNameBindingReference extends CachedReference> { + public tag: Tag; + + constructor(private inner: Reference, private truthy: Option = null, private falsy: Option = null) { super(); this.tag = inner.tag; - this.inner = inner; - this.truthy = truthy || null; - this.falsy = falsy || null; } - compute() { + compute(): Option { let { inner, truthy, falsy } = this; return inner.value() ? truthy : falsy; } diff --git a/packages/ember-glimmer/lib/utils/curly-component-state-bucket.js b/packages/ember-glimmer/lib/utils/curly-component-state-bucket.ts similarity index 56% rename from packages/ember-glimmer/lib/utils/curly-component-state-bucket.js rename to packages/ember-glimmer/lib/utils/curly-component-state-bucket.ts index 70b108bdd2c..6819a8518c7 100644 --- a/packages/ember-glimmer/lib/utils/curly-component-state-bucket.js +++ b/packages/ember-glimmer/lib/utils/curly-component-state-bucket.ts @@ -1,3 +1,16 @@ +import { Opaque } from '@glimmer/interfaces'; +import { Revision, Tagged } from '@glimmer/reference'; + +interface Environment { + isInteractive: boolean; + destroyedComponents: Component[]; +} + +interface Component { + trigger(event: string); +} + +type Finalizer = () => void; function NOOP() {} /** @@ -11,13 +24,12 @@ function NOOP() {} @private */ export default class ComponentStateBucket { - constructor(environment, component, args, finalizer) { - this.environment = environment; - this.component = component; + private classRef: Opaque = null; + private argsRevision: Revision; + + constructor(private environment: Environment, private component: Component, private args: Tagged, private finalizer: Finalizer) { this.classRef = null; - this.args = args; this.argsRevision = args.tag.value(); - this.finalizer = finalizer; } destroy() { diff --git a/packages/ember-glimmer/lib/utils/debug-stack.js b/packages/ember-glimmer/lib/utils/debug-stack.ts similarity index 92% rename from packages/ember-glimmer/lib/utils/debug-stack.js rename to packages/ember-glimmer/lib/utils/debug-stack.ts index 13c84d2d690..d527b0b4fe8 100644 --- a/packages/ember-glimmer/lib/utils/debug-stack.js +++ b/packages/ember-glimmer/lib/utils/debug-stack.ts @@ -1,11 +1,12 @@ +// @ts-check + import { DEBUG } from 'ember-env-flags'; let DebugStack; if (DEBUG) { class Element { - constructor(name) { - this.name = name; + constructor(public name: string) { } } @@ -13,9 +14,7 @@ if (DEBUG) { class EngineElement extends Element { } DebugStack = class DebugStack { - constructor() { - this._stack = []; - } + private _stack: TemplateElement[] = []; push(name) { this._stack.push(new TemplateElement(name)); From 38c22e251a3144caa8f9474d04a59979ec606f35 Mon Sep 17 00:00:00 2001 From: Steven Footea Date: Mon, 16 Oct 2017 15:57:05 -0600 Subject: [PATCH 07/24] WIP: Get rid of TS errors --- ...rotocol-for-url.js => protocol-for-url.ts} | 0 .../lib/{renderer.js => renderer.ts} | 36 ++++++++++++++++--- .../{setup-registry.js => setup-registry.ts} | 0 .../lib/{syntax.js => syntax.ts} | 0 .../lib/{template.js => template.ts} | 2 +- ...plate_registry.js => template_registry.ts} | 2 +- .../lib/templates/component.d.ts | 2 ++ .../ember-glimmer/lib/templates/empty.d.ts | 2 ++ .../ember-glimmer/lib/templates/link-to.d.ts | 2 ++ .../ember-glimmer/lib/templates/outlet.d.ts | 2 ++ packages/ember-metal/lib/index.d.ts | 7 ++++ 11 files changed, 49 insertions(+), 6 deletions(-) rename packages/ember-glimmer/lib/{protocol-for-url.js => protocol-for-url.ts} (100%) rename packages/ember-glimmer/lib/{renderer.js => renderer.ts} (93%) rename packages/ember-glimmer/lib/{setup-registry.js => setup-registry.ts} (100%) rename packages/ember-glimmer/lib/{syntax.js => syntax.ts} (100%) rename packages/ember-glimmer/lib/{template.js => template.ts} (87%) rename packages/ember-glimmer/lib/{template_registry.js => template_registry.ts} (92%) create mode 100644 packages/ember-glimmer/lib/templates/component.d.ts create mode 100644 packages/ember-glimmer/lib/templates/empty.d.ts create mode 100644 packages/ember-glimmer/lib/templates/link-to.d.ts create mode 100644 packages/ember-glimmer/lib/templates/outlet.d.ts create mode 100644 packages/ember-metal/lib/index.d.ts diff --git a/packages/ember-glimmer/lib/protocol-for-url.js b/packages/ember-glimmer/lib/protocol-for-url.ts similarity index 100% rename from packages/ember-glimmer/lib/protocol-for-url.js rename to packages/ember-glimmer/lib/protocol-for-url.ts diff --git a/packages/ember-glimmer/lib/renderer.js b/packages/ember-glimmer/lib/renderer.ts similarity index 93% rename from packages/ember-glimmer/lib/renderer.js rename to packages/ember-glimmer/lib/renderer.ts index 02423514a81..5a081a64133 100644 --- a/packages/ember-glimmer/lib/renderer.js +++ b/packages/ember-glimmer/lib/renderer.ts @@ -1,3 +1,7 @@ +interface FreeformObject { + [key: string]: any; +} + import { RootReference } from './utils/references'; import { run, @@ -19,7 +23,11 @@ import { assert } from 'ember-debug'; const { backburner } = run; class DynamicScope { - constructor(view, outletState, rootOutletState, targetObject) { + private view: any + private outletState: any + private rootOutletState: any + + constructor(view, outletState, rootOutletState) { this.view = view; this.outletState = outletState; this.rootOutletState = rootOutletState; @@ -44,6 +52,16 @@ class DynamicScope { } class RootState { + public id: any + public env: any + public root: any + public result: any + public shouldReflush: boolean + public destroyed: boolean + private _removing: boolean + public options: any + public render: any + constructor(root, env, template, self, parentElement, dynamicScope) { assert(`You cannot render \`${self.value()}\` without a template.`, template); @@ -114,7 +132,7 @@ class RootState { } } -const renderers = []; +const renderers: any[] = []; export function _resetRenderers() { renderers.length = 0; @@ -162,6 +180,16 @@ backburner.on('begin', loopBegin); backburner.on('end', loopEnd); export class Renderer { + private _env: any + private _rootTemplate: any + private _viewRegistry: any + private _destinedForDOM: any + private _destroyed: boolean + private _roots: Array + private _lastRevision: any + private _isRenderingRoots: boolean + private _removedRoots: Array + constructor(env, rootTemplate, _viewRegistry = fallbackViewRegistry, destinedForDOM = false) { this._env = env; this._rootTemplate = rootTemplate; @@ -192,7 +220,7 @@ export class Renderer { _appendDefinition(root, definition, target, outletStateReference = UNDEFINED_REFERENCE, targetObject = null) { let self = new RootReference(definition); - let dynamicScope = new DynamicScope(null, outletStateReference, outletStateReference, true, targetObject); + let dynamicScope = new DynamicScope(null, outletStateReference, outletStateReference); let rootState = new RootState(root, this._env, this._rootTemplate, self, target, dynamicScope); this._renderRoot(rootState); @@ -374,7 +402,7 @@ export class Renderer { } this._removedRoots.length = 0; - this._roots = null; + this._roots = []; // if roots were present before destroying // deregister this renderer instance diff --git a/packages/ember-glimmer/lib/setup-registry.js b/packages/ember-glimmer/lib/setup-registry.ts similarity index 100% rename from packages/ember-glimmer/lib/setup-registry.js rename to packages/ember-glimmer/lib/setup-registry.ts diff --git a/packages/ember-glimmer/lib/syntax.js b/packages/ember-glimmer/lib/syntax.ts similarity index 100% rename from packages/ember-glimmer/lib/syntax.js rename to packages/ember-glimmer/lib/syntax.ts diff --git a/packages/ember-glimmer/lib/template.js b/packages/ember-glimmer/lib/template.ts similarity index 87% rename from packages/ember-glimmer/lib/template.js rename to packages/ember-glimmer/lib/template.ts index f8e97bdd69a..96a57abb822 100644 --- a/packages/ember-glimmer/lib/template.js +++ b/packages/ember-glimmer/lib/template.ts @@ -2,7 +2,7 @@ import { OWNER } from 'ember-utils'; import { templateFactory } from '@glimmer/runtime'; export default function template(json) { - let factory = templateFactory(json); + const factory = templateFactory(json); return { id: factory.id, diff --git a/packages/ember-glimmer/lib/template_registry.js b/packages/ember-glimmer/lib/template_registry.ts similarity index 92% rename from packages/ember-glimmer/lib/template_registry.js rename to packages/ember-glimmer/lib/template_registry.ts index 5b1332129d5..c39f8472a98 100644 --- a/packages/ember-glimmer/lib/template_registry.js +++ b/packages/ember-glimmer/lib/template_registry.ts @@ -17,7 +17,7 @@ export function getTemplate(name) { } } -export function hasTemplate(name) { +export function hasTemplate(name):boolean { return TEMPLATES.hasOwnProperty(name); } diff --git a/packages/ember-glimmer/lib/templates/component.d.ts b/packages/ember-glimmer/lib/templates/component.d.ts new file mode 100644 index 00000000000..c800f6734c1 --- /dev/null +++ b/packages/ember-glimmer/lib/templates/component.d.ts @@ -0,0 +1,2 @@ +declare const TEMPLATE: any; +export default TEMPLATE; diff --git a/packages/ember-glimmer/lib/templates/empty.d.ts b/packages/ember-glimmer/lib/templates/empty.d.ts new file mode 100644 index 00000000000..c800f6734c1 --- /dev/null +++ b/packages/ember-glimmer/lib/templates/empty.d.ts @@ -0,0 +1,2 @@ +declare const TEMPLATE: any; +export default TEMPLATE; diff --git a/packages/ember-glimmer/lib/templates/link-to.d.ts b/packages/ember-glimmer/lib/templates/link-to.d.ts new file mode 100644 index 00000000000..c800f6734c1 --- /dev/null +++ b/packages/ember-glimmer/lib/templates/link-to.d.ts @@ -0,0 +1,2 @@ +declare const TEMPLATE: any; +export default TEMPLATE; diff --git a/packages/ember-glimmer/lib/templates/outlet.d.ts b/packages/ember-glimmer/lib/templates/outlet.d.ts new file mode 100644 index 00000000000..c800f6734c1 --- /dev/null +++ b/packages/ember-glimmer/lib/templates/outlet.d.ts @@ -0,0 +1,2 @@ +declare const TEMPLATE: any; +export default TEMPLATE; diff --git a/packages/ember-metal/lib/index.d.ts b/packages/ember-metal/lib/index.d.ts new file mode 100644 index 00000000000..39f5cee8005 --- /dev/null +++ b/packages/ember-metal/lib/index.d.ts @@ -0,0 +1,7 @@ +declare module 'ember-metal' { + export const run: { [key: string]: any }; + + export function setHasViews(fn: () => boolean): null; + + export function runInTransaction(context: any, methodName: string): any; +} \ No newline at end of file From 53fd94c68cd2a486af14ce749f9d58cb7f910637 Mon Sep 17 00:00:00 2001 From: Steven Footea Date: Tue, 17 Oct 2017 15:18:39 -0600 Subject: [PATCH 08/24] WIP: More types added --- packages/ember-debug/lib/index.d.ts | 2 ++ .../lib/{environment.js => environment.ts} | 30 ++++++++++++++----- .../lib/{helper.js => helper.ts} | 0 .../lib/helpers/{each-in.js => each-in.ts} | 2 +- .../lib/utils/{iterable.js => iterable.ts} | 21 ++++++++++++- .../utils/{references.js => references.ts} | 0 packages/ember-metal/lib/index.d.ts | 14 +++++++++ 7 files changed, 60 insertions(+), 9 deletions(-) rename packages/ember-glimmer/lib/{environment.js => environment.ts} (92%) rename packages/ember-glimmer/lib/{helper.js => helper.ts} (100%) rename packages/ember-glimmer/lib/helpers/{each-in.js => each-in.ts} (98%) rename packages/ember-glimmer/lib/utils/{iterable.js => iterable.ts} (92%) rename packages/ember-glimmer/lib/utils/{references.js => references.ts} (100%) diff --git a/packages/ember-debug/lib/index.d.ts b/packages/ember-debug/lib/index.d.ts index 48622e4b3e5..73a3fe98c1a 100644 --- a/packages/ember-debug/lib/index.d.ts +++ b/packages/ember-debug/lib/index.d.ts @@ -1 +1,3 @@ export function assert(message: string, test: boolean): void; + +export function warn(message: string, test: boolean, options?: any): void; \ No newline at end of file diff --git a/packages/ember-glimmer/lib/environment.js b/packages/ember-glimmer/lib/environment.ts similarity index 92% rename from packages/ember-glimmer/lib/environment.js rename to packages/ember-glimmer/lib/environment.ts index f6a8ad4fab1..fead071150b 100644 --- a/packages/ember-glimmer/lib/environment.js +++ b/packages/ember-glimmer/lib/environment.ts @@ -9,6 +9,9 @@ import { lookupComponent, constructStyleDeprecationMessage } from 'ember-views'; +import { + Reference +} from '@glimmer/reference'; import { Environment as GlimmerEnvironment, AttributeManager, @@ -16,6 +19,9 @@ import { compileLayout, getDynamicVar } from '@glimmer/runtime'; +import { + Opaque +} from '@glimmer/util'; import { CurlyComponentDefinition } from './component-managers/curly'; @@ -67,6 +73,16 @@ export default class Environment extends GlimmerEnvironment { return new this(options); } + public owner: any; + public isInteractive: boolean; + public destroyedComponents: Array; + public builtInModifiers: any; + public builtInHelpers: any; + public debugStack: any; + private _definitionCache: Cache; + private _templateCache: Cache; + private _compilerCache: Cache; + constructor({ [OWNER]: owner }) { super(...arguments); this.owner = owner; @@ -255,19 +271,19 @@ export default class Environment extends GlimmerEnvironment { return ConditionalReference.create(reference); } - iterableFor(ref, key) { + iterableFor(ref: Reference, key: string) { return createIterable(ref, key); } - scheduleInstallModifier() { + scheduleInstallModifier(modifier, manager) { if (this.isInteractive) { - super.scheduleInstallModifier(...arguments); + super.scheduleInstallModifier(modifier, manager); } } - scheduleUpdateModifier() { + scheduleUpdateModifier(modifier, manager) { if (this.isInteractive) { - super.scheduleUpdateModifier(...arguments); + super.scheduleUpdateModifier(modifier, manager); } } @@ -306,7 +322,7 @@ if (DEBUG) { } return false; })(), { id: 'ember-htmlbars.style-xss-warning' }); - super.setAttribute(...arguments); + super.setAttribute(dom, element, value); } updateAttribute(dom, element, value) { @@ -316,7 +332,7 @@ if (DEBUG) { } return false; })(), { id: 'ember-htmlbars.style-xss-warning' }); - super.updateAttribute(...arguments); + super.updateAttribute(dom, element, value); } } diff --git a/packages/ember-glimmer/lib/helper.js b/packages/ember-glimmer/lib/helper.ts similarity index 100% rename from packages/ember-glimmer/lib/helper.js rename to packages/ember-glimmer/lib/helper.ts diff --git a/packages/ember-glimmer/lib/helpers/each-in.js b/packages/ember-glimmer/lib/helpers/each-in.ts similarity index 98% rename from packages/ember-glimmer/lib/helpers/each-in.js rename to packages/ember-glimmer/lib/helpers/each-in.ts index 7e404b5fe04..2c3c548c29a 100644 --- a/packages/ember-glimmer/lib/helpers/each-in.js +++ b/packages/ember-glimmer/lib/helpers/each-in.ts @@ -111,7 +111,7 @@ import { symbol } from 'ember-utils'; */ const EACH_IN_REFERENCE = symbol('EACH_IN'); -export function isEachIn(ref) { +export function isEachIn(ref): boolean { return ref && ref[EACH_IN_REFERENCE]; } diff --git a/packages/ember-glimmer/lib/utils/iterable.js b/packages/ember-glimmer/lib/utils/iterable.ts similarity index 92% rename from packages/ember-glimmer/lib/utils/iterable.js rename to packages/ember-glimmer/lib/utils/iterable.ts index 740039740ce..20343624752 100644 --- a/packages/ember-glimmer/lib/utils/iterable.js +++ b/packages/ember-glimmer/lib/utils/iterable.ts @@ -79,6 +79,12 @@ function ensureUniqueKey(seen, key) { } class ArrayIterator { + public array: Array; + public length: number; + public keyFor: (value: any, memo: any) => any; + public position: number; + public seen: any; + constructor(array, keyFor) { this.array = array; this.length = array.length; @@ -126,6 +132,9 @@ class EmberArrayIterator extends ArrayIterator { } class ObjectKeysIterator extends ArrayIterator { + public keys: Array; + public length: number; + constructor(keys, values, keyFor) { super(values, keyFor); this.keys = keys; @@ -149,6 +158,11 @@ class EmptyIterator { const EMPTY_ITERATOR = new EmptyIterator(); class EachInIterable { + public ref: any; + public keyFor: (iterable: any) => any; + public valueTag: any; + public tag: any; + constructor(ref, keyFor) { this.ref = ref; this.keyFor = keyFor; @@ -201,6 +215,11 @@ class EachInIterable { } class ArrayIterable { + public ref: any; + public keyFor: (iterable: any) => any; + public valueTag: any; + public tag: any; + constructor(ref, keyFor) { this.ref = ref; this.keyFor = keyFor; @@ -226,7 +245,7 @@ class ArrayIterable { } else if (isEmberArray(iterable)) { return get(iterable, 'length') > 0 ? new EmberArrayIterator(iterable, keyFor) : EMPTY_ITERATOR; } else if (typeof iterable.forEach === 'function') { - let array = []; + let array: Array = []; iterable.forEach(function(item) { array.push(item); }); diff --git a/packages/ember-glimmer/lib/utils/references.js b/packages/ember-glimmer/lib/utils/references.ts similarity index 100% rename from packages/ember-glimmer/lib/utils/references.js rename to packages/ember-glimmer/lib/utils/references.ts diff --git a/packages/ember-metal/lib/index.d.ts b/packages/ember-metal/lib/index.d.ts index 39f5cee8005..c8670d0a639 100644 --- a/packages/ember-metal/lib/index.d.ts +++ b/packages/ember-metal/lib/index.d.ts @@ -4,4 +4,18 @@ declare module 'ember-metal' { export function setHasViews(fn: () => boolean): null; export function runInTransaction(context: any, methodName: string): any; + + export function _instrumentStart(name: string, _payload: (_payloadParam: any) => any, _payloadParam: any): () => void; + + export function get(obj: any, keyName: string): any; + + export function tagForProperty(object: any, propertyKey: string, _meta?: any): any; + + export function tagFor(object: any, _meta?: any): any; + + export function isProxy(value: any): boolean; + + export class Cache { + constructor(limit: number, func: (obj: any) => any, key: any, store?: any) + } } \ No newline at end of file From f57be21f39b38734420cd12bdcc4bc786c40a48b Mon Sep 17 00:00:00 2001 From: Steven Footea Date: Tue, 17 Oct 2017 15:28:08 -0600 Subject: [PATCH 09/24] Rename ember-glimmer/**/*.js to .ts --- .../lib/component-managers/{abstract.js => abstract.ts} | 0 .../ember-glimmer/lib/component-managers/{curly.js => curly.ts} | 0 .../ember-glimmer/lib/component-managers/{mount.js => mount.ts} | 0 .../ember-glimmer/lib/component-managers/{outlet.js => outlet.ts} | 0 .../ember-glimmer/lib/component-managers/{render.js => render.ts} | 0 .../ember-glimmer/lib/component-managers/{root.js => root.ts} | 0 packages/ember-glimmer/lib/{component.js => component.ts} | 0 .../ember-glimmer/lib/components/{checkbox.js => checkbox.ts} | 0 packages/ember-glimmer/lib/components/{link-to.js => link-to.ts} | 0 .../ember-glimmer/lib/components/{text_area.js => text_area.ts} | 0 .../ember-glimmer/lib/components/{text_field.js => text_field.ts} | 0 packages/ember-glimmer/lib/{dom.js => dom.ts} | 0 packages/ember-glimmer/lib/helpers/{-class.js => -class.ts} | 0 .../ember-glimmer/lib/helpers/{-html-safe.js => -html-safe.ts} | 0 .../ember-glimmer/lib/helpers/{-input-type.js => -input-type.ts} | 0 .../lib/helpers/{-normalize-class.js => -normalize-class.ts} | 0 packages/ember-glimmer/lib/helpers/{action.js => action.ts} | 0 packages/ember-glimmer/lib/helpers/{component.js => component.ts} | 0 packages/ember-glimmer/lib/helpers/{concat.js => concat.ts} | 0 packages/ember-glimmer/lib/helpers/{get.js => get.ts} | 0 packages/ember-glimmer/lib/helpers/{hash.js => hash.ts} | 0 packages/ember-glimmer/lib/helpers/{if-unless.js => if-unless.ts} | 0 packages/ember-glimmer/lib/helpers/{loc.js => loc.ts} | 0 packages/ember-glimmer/lib/helpers/{log.js => log.ts} | 0 packages/ember-glimmer/lib/helpers/{mut.js => mut.ts} | 0 .../ember-glimmer/lib/helpers/{query-param.js => query-param.ts} | 0 packages/ember-glimmer/lib/helpers/{readonly.js => readonly.ts} | 0 packages/ember-glimmer/lib/helpers/{unbound.js => unbound.ts} | 0 packages/ember-glimmer/lib/modifiers/{action.js => action.ts} | 0 .../ember-glimmer/lib/syntax/{-text-area.js => -text-area.ts} | 0 .../lib/syntax/{dynamic-component.js => dynamic-component.ts} | 0 packages/ember-glimmer/lib/syntax/{input.js => input.ts} | 0 packages/ember-glimmer/lib/syntax/{mount.js => mount.ts} | 0 packages/ember-glimmer/lib/syntax/{outlet.js => outlet.ts} | 0 packages/ember-glimmer/lib/syntax/{render.js => render.ts} | 0 packages/ember-glimmer/lib/syntax/{utils.js => utils.ts} | 0 .../ember-glimmer/lib/utils/{process-args.js => process-args.ts} | 0 packages/ember-glimmer/lib/utils/{string.js => string.ts} | 0 packages/ember-glimmer/lib/utils/{to-bool.js => to-bool.ts} | 0 packages/ember-glimmer/lib/views/{outlet.js => outlet.ts} | 0 40 files changed, 0 insertions(+), 0 deletions(-) rename packages/ember-glimmer/lib/component-managers/{abstract.js => abstract.ts} (100%) rename packages/ember-glimmer/lib/component-managers/{curly.js => curly.ts} (100%) rename packages/ember-glimmer/lib/component-managers/{mount.js => mount.ts} (100%) rename packages/ember-glimmer/lib/component-managers/{outlet.js => outlet.ts} (100%) rename packages/ember-glimmer/lib/component-managers/{render.js => render.ts} (100%) rename packages/ember-glimmer/lib/component-managers/{root.js => root.ts} (100%) rename packages/ember-glimmer/lib/{component.js => component.ts} (100%) rename packages/ember-glimmer/lib/components/{checkbox.js => checkbox.ts} (100%) rename packages/ember-glimmer/lib/components/{link-to.js => link-to.ts} (100%) rename packages/ember-glimmer/lib/components/{text_area.js => text_area.ts} (100%) rename packages/ember-glimmer/lib/components/{text_field.js => text_field.ts} (100%) rename packages/ember-glimmer/lib/{dom.js => dom.ts} (100%) rename packages/ember-glimmer/lib/helpers/{-class.js => -class.ts} (100%) rename packages/ember-glimmer/lib/helpers/{-html-safe.js => -html-safe.ts} (100%) rename packages/ember-glimmer/lib/helpers/{-input-type.js => -input-type.ts} (100%) rename packages/ember-glimmer/lib/helpers/{-normalize-class.js => -normalize-class.ts} (100%) rename packages/ember-glimmer/lib/helpers/{action.js => action.ts} (100%) rename packages/ember-glimmer/lib/helpers/{component.js => component.ts} (100%) rename packages/ember-glimmer/lib/helpers/{concat.js => concat.ts} (100%) rename packages/ember-glimmer/lib/helpers/{get.js => get.ts} (100%) rename packages/ember-glimmer/lib/helpers/{hash.js => hash.ts} (100%) rename packages/ember-glimmer/lib/helpers/{if-unless.js => if-unless.ts} (100%) rename packages/ember-glimmer/lib/helpers/{loc.js => loc.ts} (100%) rename packages/ember-glimmer/lib/helpers/{log.js => log.ts} (100%) rename packages/ember-glimmer/lib/helpers/{mut.js => mut.ts} (100%) rename packages/ember-glimmer/lib/helpers/{query-param.js => query-param.ts} (100%) rename packages/ember-glimmer/lib/helpers/{readonly.js => readonly.ts} (100%) rename packages/ember-glimmer/lib/helpers/{unbound.js => unbound.ts} (100%) rename packages/ember-glimmer/lib/modifiers/{action.js => action.ts} (100%) rename packages/ember-glimmer/lib/syntax/{-text-area.js => -text-area.ts} (100%) rename packages/ember-glimmer/lib/syntax/{dynamic-component.js => dynamic-component.ts} (100%) rename packages/ember-glimmer/lib/syntax/{input.js => input.ts} (100%) rename packages/ember-glimmer/lib/syntax/{mount.js => mount.ts} (100%) rename packages/ember-glimmer/lib/syntax/{outlet.js => outlet.ts} (100%) rename packages/ember-glimmer/lib/syntax/{render.js => render.ts} (100%) rename packages/ember-glimmer/lib/syntax/{utils.js => utils.ts} (100%) rename packages/ember-glimmer/lib/utils/{process-args.js => process-args.ts} (100%) rename packages/ember-glimmer/lib/utils/{string.js => string.ts} (100%) rename packages/ember-glimmer/lib/utils/{to-bool.js => to-bool.ts} (100%) rename packages/ember-glimmer/lib/views/{outlet.js => outlet.ts} (100%) diff --git a/packages/ember-glimmer/lib/component-managers/abstract.js b/packages/ember-glimmer/lib/component-managers/abstract.ts similarity index 100% rename from packages/ember-glimmer/lib/component-managers/abstract.js rename to packages/ember-glimmer/lib/component-managers/abstract.ts diff --git a/packages/ember-glimmer/lib/component-managers/curly.js b/packages/ember-glimmer/lib/component-managers/curly.ts similarity index 100% rename from packages/ember-glimmer/lib/component-managers/curly.js rename to packages/ember-glimmer/lib/component-managers/curly.ts diff --git a/packages/ember-glimmer/lib/component-managers/mount.js b/packages/ember-glimmer/lib/component-managers/mount.ts similarity index 100% rename from packages/ember-glimmer/lib/component-managers/mount.js rename to packages/ember-glimmer/lib/component-managers/mount.ts diff --git a/packages/ember-glimmer/lib/component-managers/outlet.js b/packages/ember-glimmer/lib/component-managers/outlet.ts similarity index 100% rename from packages/ember-glimmer/lib/component-managers/outlet.js rename to packages/ember-glimmer/lib/component-managers/outlet.ts diff --git a/packages/ember-glimmer/lib/component-managers/render.js b/packages/ember-glimmer/lib/component-managers/render.ts similarity index 100% rename from packages/ember-glimmer/lib/component-managers/render.js rename to packages/ember-glimmer/lib/component-managers/render.ts diff --git a/packages/ember-glimmer/lib/component-managers/root.js b/packages/ember-glimmer/lib/component-managers/root.ts similarity index 100% rename from packages/ember-glimmer/lib/component-managers/root.js rename to packages/ember-glimmer/lib/component-managers/root.ts diff --git a/packages/ember-glimmer/lib/component.js b/packages/ember-glimmer/lib/component.ts similarity index 100% rename from packages/ember-glimmer/lib/component.js rename to packages/ember-glimmer/lib/component.ts diff --git a/packages/ember-glimmer/lib/components/checkbox.js b/packages/ember-glimmer/lib/components/checkbox.ts similarity index 100% rename from packages/ember-glimmer/lib/components/checkbox.js rename to packages/ember-glimmer/lib/components/checkbox.ts diff --git a/packages/ember-glimmer/lib/components/link-to.js b/packages/ember-glimmer/lib/components/link-to.ts similarity index 100% rename from packages/ember-glimmer/lib/components/link-to.js rename to packages/ember-glimmer/lib/components/link-to.ts diff --git a/packages/ember-glimmer/lib/components/text_area.js b/packages/ember-glimmer/lib/components/text_area.ts similarity index 100% rename from packages/ember-glimmer/lib/components/text_area.js rename to packages/ember-glimmer/lib/components/text_area.ts diff --git a/packages/ember-glimmer/lib/components/text_field.js b/packages/ember-glimmer/lib/components/text_field.ts similarity index 100% rename from packages/ember-glimmer/lib/components/text_field.js rename to packages/ember-glimmer/lib/components/text_field.ts diff --git a/packages/ember-glimmer/lib/dom.js b/packages/ember-glimmer/lib/dom.ts similarity index 100% rename from packages/ember-glimmer/lib/dom.js rename to packages/ember-glimmer/lib/dom.ts diff --git a/packages/ember-glimmer/lib/helpers/-class.js b/packages/ember-glimmer/lib/helpers/-class.ts similarity index 100% rename from packages/ember-glimmer/lib/helpers/-class.js rename to packages/ember-glimmer/lib/helpers/-class.ts diff --git a/packages/ember-glimmer/lib/helpers/-html-safe.js b/packages/ember-glimmer/lib/helpers/-html-safe.ts similarity index 100% rename from packages/ember-glimmer/lib/helpers/-html-safe.js rename to packages/ember-glimmer/lib/helpers/-html-safe.ts diff --git a/packages/ember-glimmer/lib/helpers/-input-type.js b/packages/ember-glimmer/lib/helpers/-input-type.ts similarity index 100% rename from packages/ember-glimmer/lib/helpers/-input-type.js rename to packages/ember-glimmer/lib/helpers/-input-type.ts diff --git a/packages/ember-glimmer/lib/helpers/-normalize-class.js b/packages/ember-glimmer/lib/helpers/-normalize-class.ts similarity index 100% rename from packages/ember-glimmer/lib/helpers/-normalize-class.js rename to packages/ember-glimmer/lib/helpers/-normalize-class.ts diff --git a/packages/ember-glimmer/lib/helpers/action.js b/packages/ember-glimmer/lib/helpers/action.ts similarity index 100% rename from packages/ember-glimmer/lib/helpers/action.js rename to packages/ember-glimmer/lib/helpers/action.ts diff --git a/packages/ember-glimmer/lib/helpers/component.js b/packages/ember-glimmer/lib/helpers/component.ts similarity index 100% rename from packages/ember-glimmer/lib/helpers/component.js rename to packages/ember-glimmer/lib/helpers/component.ts diff --git a/packages/ember-glimmer/lib/helpers/concat.js b/packages/ember-glimmer/lib/helpers/concat.ts similarity index 100% rename from packages/ember-glimmer/lib/helpers/concat.js rename to packages/ember-glimmer/lib/helpers/concat.ts diff --git a/packages/ember-glimmer/lib/helpers/get.js b/packages/ember-glimmer/lib/helpers/get.ts similarity index 100% rename from packages/ember-glimmer/lib/helpers/get.js rename to packages/ember-glimmer/lib/helpers/get.ts diff --git a/packages/ember-glimmer/lib/helpers/hash.js b/packages/ember-glimmer/lib/helpers/hash.ts similarity index 100% rename from packages/ember-glimmer/lib/helpers/hash.js rename to packages/ember-glimmer/lib/helpers/hash.ts diff --git a/packages/ember-glimmer/lib/helpers/if-unless.js b/packages/ember-glimmer/lib/helpers/if-unless.ts similarity index 100% rename from packages/ember-glimmer/lib/helpers/if-unless.js rename to packages/ember-glimmer/lib/helpers/if-unless.ts diff --git a/packages/ember-glimmer/lib/helpers/loc.js b/packages/ember-glimmer/lib/helpers/loc.ts similarity index 100% rename from packages/ember-glimmer/lib/helpers/loc.js rename to packages/ember-glimmer/lib/helpers/loc.ts diff --git a/packages/ember-glimmer/lib/helpers/log.js b/packages/ember-glimmer/lib/helpers/log.ts similarity index 100% rename from packages/ember-glimmer/lib/helpers/log.js rename to packages/ember-glimmer/lib/helpers/log.ts diff --git a/packages/ember-glimmer/lib/helpers/mut.js b/packages/ember-glimmer/lib/helpers/mut.ts similarity index 100% rename from packages/ember-glimmer/lib/helpers/mut.js rename to packages/ember-glimmer/lib/helpers/mut.ts diff --git a/packages/ember-glimmer/lib/helpers/query-param.js b/packages/ember-glimmer/lib/helpers/query-param.ts similarity index 100% rename from packages/ember-glimmer/lib/helpers/query-param.js rename to packages/ember-glimmer/lib/helpers/query-param.ts diff --git a/packages/ember-glimmer/lib/helpers/readonly.js b/packages/ember-glimmer/lib/helpers/readonly.ts similarity index 100% rename from packages/ember-glimmer/lib/helpers/readonly.js rename to packages/ember-glimmer/lib/helpers/readonly.ts diff --git a/packages/ember-glimmer/lib/helpers/unbound.js b/packages/ember-glimmer/lib/helpers/unbound.ts similarity index 100% rename from packages/ember-glimmer/lib/helpers/unbound.js rename to packages/ember-glimmer/lib/helpers/unbound.ts diff --git a/packages/ember-glimmer/lib/modifiers/action.js b/packages/ember-glimmer/lib/modifiers/action.ts similarity index 100% rename from packages/ember-glimmer/lib/modifiers/action.js rename to packages/ember-glimmer/lib/modifiers/action.ts diff --git a/packages/ember-glimmer/lib/syntax/-text-area.js b/packages/ember-glimmer/lib/syntax/-text-area.ts similarity index 100% rename from packages/ember-glimmer/lib/syntax/-text-area.js rename to packages/ember-glimmer/lib/syntax/-text-area.ts diff --git a/packages/ember-glimmer/lib/syntax/dynamic-component.js b/packages/ember-glimmer/lib/syntax/dynamic-component.ts similarity index 100% rename from packages/ember-glimmer/lib/syntax/dynamic-component.js rename to packages/ember-glimmer/lib/syntax/dynamic-component.ts diff --git a/packages/ember-glimmer/lib/syntax/input.js b/packages/ember-glimmer/lib/syntax/input.ts similarity index 100% rename from packages/ember-glimmer/lib/syntax/input.js rename to packages/ember-glimmer/lib/syntax/input.ts diff --git a/packages/ember-glimmer/lib/syntax/mount.js b/packages/ember-glimmer/lib/syntax/mount.ts similarity index 100% rename from packages/ember-glimmer/lib/syntax/mount.js rename to packages/ember-glimmer/lib/syntax/mount.ts diff --git a/packages/ember-glimmer/lib/syntax/outlet.js b/packages/ember-glimmer/lib/syntax/outlet.ts similarity index 100% rename from packages/ember-glimmer/lib/syntax/outlet.js rename to packages/ember-glimmer/lib/syntax/outlet.ts diff --git a/packages/ember-glimmer/lib/syntax/render.js b/packages/ember-glimmer/lib/syntax/render.ts similarity index 100% rename from packages/ember-glimmer/lib/syntax/render.js rename to packages/ember-glimmer/lib/syntax/render.ts diff --git a/packages/ember-glimmer/lib/syntax/utils.js b/packages/ember-glimmer/lib/syntax/utils.ts similarity index 100% rename from packages/ember-glimmer/lib/syntax/utils.js rename to packages/ember-glimmer/lib/syntax/utils.ts diff --git a/packages/ember-glimmer/lib/utils/process-args.js b/packages/ember-glimmer/lib/utils/process-args.ts similarity index 100% rename from packages/ember-glimmer/lib/utils/process-args.js rename to packages/ember-glimmer/lib/utils/process-args.ts diff --git a/packages/ember-glimmer/lib/utils/string.js b/packages/ember-glimmer/lib/utils/string.ts similarity index 100% rename from packages/ember-glimmer/lib/utils/string.js rename to packages/ember-glimmer/lib/utils/string.ts diff --git a/packages/ember-glimmer/lib/utils/to-bool.js b/packages/ember-glimmer/lib/utils/to-bool.ts similarity index 100% rename from packages/ember-glimmer/lib/utils/to-bool.js rename to packages/ember-glimmer/lib/utils/to-bool.ts diff --git a/packages/ember-glimmer/lib/views/outlet.js b/packages/ember-glimmer/lib/views/outlet.ts similarity index 100% rename from packages/ember-glimmer/lib/views/outlet.js rename to packages/ember-glimmer/lib/views/outlet.ts From 3d32cc0e8aea7b5664f697dd3ca1f9e3cc2e7a18 Mon Sep 17 00:00:00 2001 From: Steven Footea Date: Wed, 18 Oct 2017 11:23:32 -0600 Subject: [PATCH 10/24] Modify build to handle typescript --- broccoli/glimmer-template-compiler.js | 2 +- broccoli/packages.js | 13 +++++++++---- ember-cli-build.js | 5 ++++- tsconfig.json | 20 ++++++-------------- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/broccoli/glimmer-template-compiler.js b/broccoli/glimmer-template-compiler.js index 85f46f8e76f..7c4f49314b6 100644 --- a/broccoli/glimmer-template-compiler.js +++ b/broccoli/glimmer-template-compiler.js @@ -21,7 +21,7 @@ function GlimmerTemplatePrecompiler (inputTree, options) { } GlimmerTemplatePrecompiler.prototype.extensions = ['hbs']; -GlimmerTemplatePrecompiler.prototype.targetExtension = 'ts'; +GlimmerTemplatePrecompiler.prototype.targetExtension = 'js'; GlimmerTemplatePrecompiler.prototype.baseDir = function() { return __dirname; diff --git a/broccoli/packages.js b/broccoli/packages.js index 4cc6298de0e..5d560f7a334 100644 --- a/broccoli/packages.js +++ b/broccoli/packages.js @@ -7,6 +7,7 @@ const Funnel = require('broccoli-funnel'); const filterTypeScript = require('broccoli-typescript-compiler').filterTypeScript; const TypeScriptPlugin = require('broccoli-typescript-compiler').TypeScriptPlugin; const BroccoliDebug = require('broccoli-debug'); +const MergeTrees = require('broccoli-merge-trees'); const findLib = require('./find-lib'); const funnelLib = require('./funnel-lib'); const { VERSION } = require('./version'); @@ -63,7 +64,7 @@ module.exports.qunit = function _qunit() { module.exports.emberGlimmerES = function _emberGlimmerES() { let input = new Funnel('packages/ember-glimmer/lib', { - destDir: 'packages/ember-glimmer' + destDir: 'packages/ember-glimmer/lib' }); let debuggedInput = debugTree(input, 'ember-glimmer:input'); @@ -76,11 +77,15 @@ module.exports.emberGlimmerES = function _emberGlimmerES() { let debuggedCompiledTemplatesAndTypeScript = debugTree(compiledTemplatesAndTypescript, 'ember-glimmer:templates-output'); - let typescriptCompiled = new TypeScriptPlugin(debuggedCompiledTemplatesAndTypeScript, { - compilerOptions: { allowJs: true } + let typescriptCompiled = filterTypeScript(debuggedCompiledTemplatesAndTypeScript); + + let funneled = new Funnel(typescriptCompiled, { + getDestinationPath(path) { + return path.replace('/lib/', '/').replace('packages/', '/'); + } }); - return debugTree(typescriptCompiled, 'ember-glimmer:output'); + return debugTree(funneled, 'ember-glimmer:output'); } module.exports.handlebarsES = function _handlebars() { diff --git a/ember-cli-build.js b/ember-cli-build.js index dd95110e34d..a143765fc4d 100644 --- a/ember-cli-build.js +++ b/ember-cli-build.js @@ -73,7 +73,10 @@ module.exports = function(options) { let inlineParser = toES5(handlebarsES(), { annotation: 'handlebars' }); let tokenizer = toES5(simpleHTMLTokenizerES(), { annotation: 'tokenizer' }); let rsvp = toES5(rsvpES(), { annotation: 'rsvp' }); - let emberMetal = new Funnel('packages/ember-metal/lib', { destDir: '/' }); + let emberMetal = new Funnel('packages/ember-metal/lib', { + destDir: '/', + include: ['**/*.js'] + }); let emberMetalES5 = rollupEmberMetal(emberMetal); let emberConsole = emberPkgES('ember-console', SHOULD_ROLLUP, ['ember-environment']); let emberConsoleES5 = toES5(emberConsole, { annotation: 'ember-console' }); diff --git a/tsconfig.json b/tsconfig.json index c151f96c030..94a6020c589 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -19,29 +19,21 @@ // "noUnusedLocals": true, // "noUnusedParameters": true, // "allowUnreachableCode": false, - "strictNullChecks": true, + // "strictNullChecks": true, // "noImplicitReturns": true, // "noImplicitThis": true, "newLine": "LF", - "noEmit": false, - "allowJs": true, + "noEmit": true, + "allowJs": false, "paths": { "*": ["*/lib"] } }, - "include": [ - "packages/**/*.ts", - "packages/**/*.js" - ], - - "exclude": [ - "dist", - "demos", - "tmp", - "node_modules", - ".vscode" + "files": [ + "packages/ember-glimmer/lib/index.ts" ] + } From 74b2679634955f54bc424c486a64d44c93c13b42 Mon Sep 17 00:00:00 2001 From: Steven Footea Date: Thu, 19 Oct 2017 05:12:43 -0600 Subject: [PATCH 11/24] Fix missing property and other minor TS errors --- packages/ember-debug/lib/index.d.ts | 6 ++- packages/ember-glimmer/externs.d.ts | 9 ++++ .../lib/component-managers/abstract.ts | 12 +++-- .../lib/component-managers/curly.ts | 27 +++++++--- .../lib/component-managers/mount.ts | 20 ++++++-- .../lib/component-managers/outlet.ts | 15 +++++- .../lib/component-managers/render.ts | 6 ++- .../lib/component-managers/root.ts | 4 +- packages/ember-glimmer/lib/environment.ts | 6 ++- packages/ember-glimmer/lib/helpers/action.ts | 2 +- .../ember-glimmer/lib/helpers/component.ts | 8 +++ packages/ember-glimmer/lib/helpers/get.ts | 7 +++ .../ember-glimmer/lib/helpers/if-unless.ts | 6 +++ .../ember-glimmer/lib/modifiers/action.ts | 13 ++++- packages/ember-glimmer/lib/syntax.ts | 2 +- .../lib/syntax/dynamic-component.ts | 8 ++- packages/ember-glimmer/lib/syntax/mount.ts | 6 +++ packages/ember-glimmer/lib/syntax/outlet.ts | 7 +++ packages/ember-glimmer/lib/utils/bindings.ts | 6 +-- .../lib/utils/curly-component-state-bucket.ts | 2 +- .../ember-glimmer/lib/utils/process-args.ts | 1 + .../ember-glimmer/lib/utils/references.ts | 38 ++++++++++++-- packages/ember-glimmer/lib/utils/string.ts | 2 + packages/ember-glimmer/lib/views/outlet.ts | 17 +++++++ packages/ember-metal/lib/index.d.ts | 50 ++++++++++++++----- packages/node-module/lib/index.d.ts | 3 ++ 26 files changed, 238 insertions(+), 45 deletions(-) create mode 100644 packages/node-module/lib/index.d.ts diff --git a/packages/ember-debug/lib/index.d.ts b/packages/ember-debug/lib/index.d.ts index 73a3fe98c1a..844e29805a4 100644 --- a/packages/ember-debug/lib/index.d.ts +++ b/packages/ember-debug/lib/index.d.ts @@ -1,3 +1,5 @@ -export function assert(message: string, test: boolean): void; +export function assert(message: string, test?: boolean): void; -export function warn(message: string, test: boolean, options?: any): void; \ No newline at end of file +export function warn(message: string, test: boolean, options?: any): void; + +export function deprecate(message: string, test: boolean, options?: any): void; \ No newline at end of file diff --git a/packages/ember-glimmer/externs.d.ts b/packages/ember-glimmer/externs.d.ts index 0f0a26704c6..7df0a77fc64 100644 --- a/packages/ember-glimmer/externs.d.ts +++ b/packages/ember-glimmer/externs.d.ts @@ -1,3 +1,12 @@ +declare module 'ember/features' { + export const EMBER_MODULE_UNIFICATION: any; + export const GLIMMER_CUSTOM_COMPONENT_MANAGER: any; + export const EMBER_ENGINES_MOUNT_PARAMS: any; + export const EMBER_GLIMMER_DETECT_BACKTRACKING_RERENDER: any; + export const EMBER_GLIMMER_ALLOW_BACKTRACKING_RERENDER: any; + export const MANDATORY_SETTER: any; +} + declare module 'ember-env-flags' { export const DEBUG: boolean; } diff --git a/packages/ember-glimmer/lib/component-managers/abstract.ts b/packages/ember-glimmer/lib/component-managers/abstract.ts index 6884df937f0..da6ada534e5 100644 --- a/packages/ember-glimmer/lib/component-managers/abstract.ts +++ b/packages/ember-glimmer/lib/component-managers/abstract.ts @@ -4,11 +4,15 @@ import { DEBUG } from 'ember-env-flags'; // https://github.com/glimmerjs/glimmer-vm/blob/v0.24.0-beta.4/packages/%40glimmer/runtime/lib/component/interfaces.ts#L21 export default class AbstractManager { + public debugStack: any; + public _pushToDebugStack: (name: string, environment: any) => void; + public _pushEngineToDebugStack: (name: string, environment: any) => void; + constructor() { this.debugStack = undefined; } - prepareArgs(definition, args) { + prepareArgs(definition, args): any | null { return null; } @@ -43,7 +47,7 @@ export default class AbstractManager { // inheritors should also call `this._pushToDebugStack` // to ensure the rerendering assertion messages are // properly maintained - update(bucket, dynamicScope) { } + update(bucket, dynamicScope?) { } // inheritors should also call `this.debugStack.pop()` to // ensure the rerendering assertion messages are properly @@ -56,12 +60,12 @@ export default class AbstractManager { } if (DEBUG) { - AbstractManager.prototype._pushToDebugStack = function(name, environment) { + AbstractManager.prototype._pushToDebugStack = function(name: string, environment) { this.debugStack = environment.debugStack; this.debugStack.push(name); }; - AbstractManager.prototype._pushEngineToDebugStack = function(name, environment) { + AbstractManager.prototype._pushEngineToDebugStack = function(name: string, environment) { this.debugStack = environment.debugStack; this.debugStack.pushEngine(name); }; diff --git a/packages/ember-glimmer/lib/component-managers/curly.ts b/packages/ember-glimmer/lib/component-managers/curly.ts index 4294fdc35b6..8d6573a1054 100644 --- a/packages/ember-glimmer/lib/component-managers/curly.ts +++ b/packages/ember-glimmer/lib/component-managers/curly.ts @@ -1,4 +1,8 @@ -import { OWNER, assign } from 'ember-utils'; +import { + Opaque, + OWNER, + assign +} from 'ember-utils'; import { combineTagged } from '@glimmer/reference'; import { PrimitiveReference, @@ -41,15 +45,15 @@ function aliasIdToElementId(args, props) { } // We must traverse the attributeBindings in reverse keeping track of -// what has already been applied. This is essentially refining the concated +// what has already been applied. This is essentially refining the concatenated // properties applying right to left. function applyAttributeBindings(element, attributeBindings, component, operations) { - let seen = []; + let seen: Array = []; let i = attributeBindings.length - 1; while (i !== -1) { let binding = attributeBindings[i]; - let parsed = AttributeBinding.parse(binding); + let parsed: Array = AttributeBinding.parse(binding); let attribute = parsed[1]; if (seen.indexOf(attribute) === -1) { @@ -80,6 +84,9 @@ function ariaRole(vm) { } class CurlyComponentLayoutCompiler { + static id: string; + public template: any; + constructor(template) { this.template = template; } @@ -95,6 +102,9 @@ class CurlyComponentLayoutCompiler { CurlyComponentLayoutCompiler.id = 'curly'; export class PositionalArgumentReference { + public tag: any; + private _references: any; + constructor(references) { this.tag = combineTagged(references); this._references = references; @@ -303,7 +313,7 @@ export default class CurlyComponentManager extends AbstractManager { } } - update(bucket, _, dynamicScope) { + update(bucket) { let { component, args, argsRevision, environment } = bucket; if (DEBUG) { @@ -416,8 +426,11 @@ export function rerenderInstrumentDetails(component) { const MANAGER = new CurlyComponentManager(); -export class CurlyComponentDefinition extends ComponentDefinition { - constructor(name, ComponentClass, template, args, customManager) { +export class CurlyComponentDefinition extends ComponentDefinition { + public template: any; + public args: any; + + constructor(name, ComponentClass, template, args, customManager?) { super(name, customManager || MANAGER, ComponentClass); this.template = template; this.args = args; diff --git a/packages/ember-glimmer/lib/component-managers/mount.ts b/packages/ember-glimmer/lib/component-managers/mount.ts index a30a90ce4d2..0c7f3668ff8 100644 --- a/packages/ember-glimmer/lib/component-managers/mount.ts +++ b/packages/ember-glimmer/lib/component-managers/mount.ts @@ -2,6 +2,9 @@ import { ComponentDefinition } from '@glimmer/runtime'; import { UNDEFINED_REFERENCE } from '@glimmer/reference'; +import { + Opaque +} from '@glimmer/util'; import { DEBUG } from 'ember-env-flags'; import { RootReference } from '../utils/references'; @@ -10,6 +13,17 @@ import AbstractManager from './abstract'; import { generateControllerFactory } from 'ember-routing'; import { EMBER_ENGINES_MOUNT_PARAMS } from 'ember/features'; +//TODO: remove these stubbed interfaces when better typing is in place +interface engineType { + boot(): void; +}; + +interface bucketType { + modelReference?: any; + engine: engineType; +}; + + class MountManager extends AbstractManager { prepareArgs(definition, args) { return null; @@ -22,11 +36,11 @@ class MountManager extends AbstractManager { dynamicScope.outletState = UNDEFINED_REFERENCE; - let engine = environment.owner.buildChildEngineInstance(name); + let engine: engineType = environment.owner.buildChildEngineInstance(name); engine.boot(); - let bucket = { engine }; + let bucket: bucketType = { engine }; if (EMBER_ENGINES_MOUNT_PARAMS) { bucket.modelReference = args.named.get('model'); @@ -81,7 +95,7 @@ class MountManager extends AbstractManager { const MOUNT_MANAGER = new MountManager(); -export class MountDefinition extends ComponentDefinition { +export class MountDefinition extends ComponentDefinition { constructor(name) { super(name, MOUNT_MANAGER, null); } diff --git a/packages/ember-glimmer/lib/component-managers/outlet.ts b/packages/ember-glimmer/lib/component-managers/outlet.ts index 7797b5b06c8..cf5da00f177 100644 --- a/packages/ember-glimmer/lib/component-managers/outlet.ts +++ b/packages/ember-glimmer/lib/component-managers/outlet.ts @@ -14,6 +14,9 @@ function instrumentationPayload({ render: { name, outlet } }) { function NOOP() {} class StateBucket { + public outletState: any; + public finalizer: any; + constructor(outletState) { this.outletState = outletState; this.instrument(); @@ -76,7 +79,8 @@ class TopLevelOutletComponentManager extends OutletComponentManager { const TOP_LEVEL_MANAGER = new TopLevelOutletComponentManager(); -export class TopLevelOutletComponentDefinition extends ComponentDefinition { +export class TopLevelOutletComponentDefinition extends ComponentDefinition { + public template: any; constructor(instance) { super('outlet', TOP_LEVEL_MANAGER, instance); this.template = instance.template; @@ -85,6 +89,8 @@ export class TopLevelOutletComponentDefinition extends ComponentDefinition { } class TopLevelOutletLayoutCompiler { + static id: string; + public template: any; constructor(template) { this.template = template; } @@ -99,7 +105,10 @@ class TopLevelOutletLayoutCompiler { TopLevelOutletLayoutCompiler.id = 'top-level-outlet'; -export class OutletComponentDefinition extends ComponentDefinition { +export class OutletComponentDefinition extends ComponentDefinition { + public outletName: string; + public template: any; + constructor(outletName, template) { super('outlet', MANAGER, null); this.outletName = outletName; @@ -109,6 +118,8 @@ export class OutletComponentDefinition extends ComponentDefinition { } export class OutletLayoutCompiler { + static id: string; + public template: any; constructor(template) { this.template = template; } diff --git a/packages/ember-glimmer/lib/component-managers/render.ts b/packages/ember-glimmer/lib/component-managers/render.ts index 02579d0a7d6..f89a06fbd79 100644 --- a/packages/ember-glimmer/lib/component-managers/render.ts +++ b/packages/ember-glimmer/lib/component-managers/render.ts @@ -74,7 +74,11 @@ class NonSingletonRenderManager extends AbstractRenderManager { export const NON_SINGLETON_RENDER_MANAGER = new NonSingletonRenderManager(); -export class RenderDefinition extends ComponentDefinition { +export class RenderDefinition extends ComponentDefinition { + public name: string; + public template: any; + public env: any; + constructor(name, template, env, manager) { super('render', manager, null); diff --git a/packages/ember-glimmer/lib/component-managers/root.ts b/packages/ember-glimmer/lib/component-managers/root.ts index 04795798624..0ecba2a3314 100644 --- a/packages/ember-glimmer/lib/component-managers/root.ts +++ b/packages/ember-glimmer/lib/component-managers/root.ts @@ -49,7 +49,9 @@ class RootComponentManager extends CurlyComponentManager { const ROOT_MANAGER = new RootComponentManager(); -export class RootComponentDefinition extends ComponentDefinition { +export class RootComponentDefinition extends ComponentDefinition { + public template: any; + public args: any; constructor(instance) { super('-root', ROOT_MANAGER, { class: instance.constructor, diff --git a/packages/ember-glimmer/lib/environment.ts b/packages/ember-glimmer/lib/environment.ts index fead071150b..a1bef02a7dd 100644 --- a/packages/ember-glimmer/lib/environment.ts +++ b/packages/ember-glimmer/lib/environment.ts @@ -1,7 +1,7 @@ +/// import { guidFor, OWNER } from 'ember-utils'; import { Cache, _instrumentStart } from 'ember-metal'; import { assert, warn } from 'ember-debug'; -import { EMBER_MODULE_UNIFICATION } from 'ember/features'; import { DEBUG } from 'ember-env-flags'; import { lookupPartial, @@ -61,7 +61,8 @@ import installPlatformSpecificProtocolForURL from './protocol-for-url'; import { default as ActionModifierManager } from './modifiers/action'; import { - GLIMMER_CUSTOM_COMPONENT_MANAGER + GLIMMER_CUSTOM_COMPONENT_MANAGER, + EMBER_MODULE_UNIFICATION } from 'ember/features'; function instrumentationPayload(name) { @@ -79,6 +80,7 @@ export default class Environment extends GlimmerEnvironment { public builtInModifiers: any; public builtInHelpers: any; public debugStack: any; + public inTransaction: boolean; private _definitionCache: Cache; private _templateCache: Cache; private _compilerCache: Cache; diff --git a/packages/ember-glimmer/lib/helpers/action.ts b/packages/ember-glimmer/lib/helpers/action.ts index 70d9a5c8113..12214373c1c 100644 --- a/packages/ember-glimmer/lib/helpers/action.ts +++ b/packages/ember-glimmer/lib/helpers/action.ts @@ -270,7 +270,7 @@ export const ACTION = symbol('ACTION'); @for Ember.Templates.helpers @public */ -export default function(vm, args) { +export default function(vm, args): UnboundReference { let { named, positional } = args; let capturedArgs = positional.capture(); diff --git a/packages/ember-glimmer/lib/helpers/component.ts b/packages/ember-glimmer/lib/helpers/component.ts index ac11fdd0702..e161660efa1 100644 --- a/packages/ember-glimmer/lib/helpers/component.ts +++ b/packages/ember-glimmer/lib/helpers/component.ts @@ -144,6 +144,14 @@ import { assert } from 'ember-debug'; @public */ export class ClosureComponentReference extends CachedReference { + public defRef: any; + public tag: any; + public args: any; + public meta: any; + public env: any; + public lastDefinition: any; + public lastName: string; + static create(args, meta, env) { return new ClosureComponentReference(args, meta, env); } diff --git a/packages/ember-glimmer/lib/helpers/get.ts b/packages/ember-glimmer/lib/helpers/get.ts index 8d41d2d51e5..265c14da981 100644 --- a/packages/ember-glimmer/lib/helpers/get.ts +++ b/packages/ember-glimmer/lib/helpers/get.ts @@ -65,6 +65,13 @@ export default function(vm, args) { } class GetHelperReference extends CachedReference { + public sourceReference: any; + public pathReference: any; + public lastPath: any; + public innerReference: any; + public innerTag: UpdatableTag; + public tag: any; + static create(sourceReference, pathReference) { if (isConst(pathReference)) { let parts = pathReference.value().split('.'); diff --git a/packages/ember-glimmer/lib/helpers/if-unless.ts b/packages/ember-glimmer/lib/helpers/if-unless.ts index 20191aaa0bd..609eacd74da 100644 --- a/packages/ember-glimmer/lib/helpers/if-unless.ts +++ b/packages/ember-glimmer/lib/helpers/if-unless.ts @@ -15,6 +15,12 @@ import { } from '@glimmer/reference'; class ConditionalHelperReference extends CachedReference { + public branchTag: UpdatableTag; + public tag: any; + public cond: any; + public truthy: any; + public falsy: any; + static create(_condRef, truthyRef, falsyRef) { let condRef = ConditionalReference.create(_condRef); if (isConst(condRef)) { diff --git a/packages/ember-glimmer/lib/modifiers/action.ts b/packages/ember-glimmer/lib/modifiers/action.ts index 28a4ea05188..3e590226cf1 100644 --- a/packages/ember-glimmer/lib/modifiers/action.ts +++ b/packages/ember-glimmer/lib/modifiers/action.ts @@ -53,6 +53,16 @@ export let ActionHelper = { }; export class ActionState { + public element: HTMLElement; + public actionId: any; + public actionName: any; + public actionArgs: any; + public namedArgs: any; + public positional: any; + public implicitTarget: any; + public dom: any; + public eventName: any; + constructor(element, actionId, actionName, actionArgs, namedArgs, positionalArgs, implicitTarget, dom) { this.element = element; this.actionId = actionId; @@ -115,7 +125,8 @@ export class ActionState { let args = this.getActionArgs(); let payload = { args, - target + target, + name: null }; if (typeof actionName[INVOKE] === 'function') { flaggedInstrument('interaction.ember-action', payload, () => { diff --git a/packages/ember-glimmer/lib/syntax.ts b/packages/ember-glimmer/lib/syntax.ts index 02c416a385f..1f0238cea3d 100644 --- a/packages/ember-glimmer/lib/syntax.ts +++ b/packages/ember-glimmer/lib/syntax.ts @@ -53,7 +53,7 @@ function refineBlockSyntax(name, params, hash, _default, inverse, builder) { return false; } -export const experimentalMacros = []; +export const experimentalMacros: Array = []; // This is a private API to allow for experimental macros // to be created in user space. Registering a macro should diff --git a/packages/ember-glimmer/lib/syntax/dynamic-component.ts b/packages/ember-glimmer/lib/syntax/dynamic-component.ts index e66f939d27b..bdb893d71b8 100644 --- a/packages/ember-glimmer/lib/syntax/dynamic-component.ts +++ b/packages/ember-glimmer/lib/syntax/dynamic-component.ts @@ -9,7 +9,7 @@ function dynamicComponentFor(vm, args, meta) { let env = vm.env; let nameRef = args.positional.at(0); - return new DynamicComponentReference({ nameRef, env, meta }); + return new DynamicComponentReference({ nameRef, env, meta, args: null }); } export function dynamicComponentMacro(params, hash, _default, inverse, builder) { @@ -34,6 +34,12 @@ export function inlineComponentMacro(name, params, hash, builder) { } class DynamicComponentReference { + public tag: any; + public nameRef: any; + public env: any; + public meta: any; + public args: any; + constructor({ nameRef, env, meta, args }) { this.tag = nameRef.tag; this.nameRef = nameRef; diff --git a/packages/ember-glimmer/lib/syntax/mount.ts b/packages/ember-glimmer/lib/syntax/mount.ts index 1a0e58b692e..6080ea415aa 100644 --- a/packages/ember-glimmer/lib/syntax/mount.ts +++ b/packages/ember-glimmer/lib/syntax/mount.ts @@ -75,6 +75,12 @@ export function mountMacro(name, params, hash, builder) { } class DynamicEngineReference { + public tag: any; + public nameRef: any; + public env: any; + public meta: any; + private _lastName: any; + private _lastDef: any; constructor({ nameRef, env, meta }) { this.tag = nameRef.tag; this.nameRef = nameRef; diff --git a/packages/ember-glimmer/lib/syntax/outlet.ts b/packages/ember-glimmer/lib/syntax/outlet.ts index e7c48767f76..6602168d49d 100644 --- a/packages/ember-glimmer/lib/syntax/outlet.ts +++ b/packages/ember-glimmer/lib/syntax/outlet.ts @@ -6,6 +6,13 @@ import { import { OutletComponentDefinition } from '../component-managers/outlet'; class OutletComponentReference { + public outletNameRef: any; + public parentOutletStateRef: any; + public definition: any; + public lastState: any; + public outletStateTag: UpdatableTag; + public tag: any; + constructor(outletNameRef, parentOutletStateRef) { this.outletNameRef = outletNameRef; this.parentOutletStateRef = parentOutletStateRef; diff --git a/packages/ember-glimmer/lib/utils/bindings.ts b/packages/ember-glimmer/lib/utils/bindings.ts index 77425fe423c..695e8714fcb 100644 --- a/packages/ember-glimmer/lib/utils/bindings.ts +++ b/packages/ember-glimmer/lib/utils/bindings.ts @@ -14,7 +14,7 @@ import { assert } from 'ember-debug'; import { get } from 'ember-metal'; import { String as StringUtils } from 'ember-runtime'; import { ROOT_REF } from '../component'; -import { htmlSafe, isHTMLSafe } from './string'; +import { htmlSafe, isHTMLSafe, SafeString } from './string'; function referenceForKey(component, key) { return component[ROOT_REF].get(key); @@ -103,7 +103,7 @@ export const AttributeBinding = { const DISPLAY_NONE = 'display: none;'; const SAFE_DISPLAY_NONE = htmlSafe(DISPLAY_NONE); -class StyleBindingReference extends CachedReference { +class StyleBindingReference extends CachedReference { public tag: Tag; constructor(private inner: Reference, private isVisible: Reference) { super(); @@ -111,7 +111,7 @@ class StyleBindingReference extends CachedReference { this.tag = combine([inner.tag, isVisible.tag]); } - compute(): string { + compute(): string | SafeString { let value = this.inner.value(); let isVisible = this.isVisible.value(); diff --git a/packages/ember-glimmer/lib/utils/curly-component-state-bucket.ts b/packages/ember-glimmer/lib/utils/curly-component-state-bucket.ts index 6819a8518c7..3f7b851da2b 100644 --- a/packages/ember-glimmer/lib/utils/curly-component-state-bucket.ts +++ b/packages/ember-glimmer/lib/utils/curly-component-state-bucket.ts @@ -24,7 +24,7 @@ function NOOP() {} @private */ export default class ComponentStateBucket { - private classRef: Opaque = null; + public classRef: Opaque = null; private argsRevision: Revision; constructor(private environment: Environment, private component: Component, private args: Tagged, private finalizer: Finalizer) { diff --git a/packages/ember-glimmer/lib/utils/process-args.ts b/packages/ember-glimmer/lib/utils/process-args.ts index 2fa45ee71f7..3c9cdb8848e 100644 --- a/packages/ember-glimmer/lib/utils/process-args.ts +++ b/packages/ember-glimmer/lib/utils/process-args.ts @@ -38,6 +38,7 @@ export function processComponentArgs(namedArgs) { const REF = symbol('REF'); class MutableCell { + public value: any; constructor(ref, value) { this[MUTABLE_CELL] = true; this[REF] = ref; diff --git a/packages/ember-glimmer/lib/utils/references.ts b/packages/ember-glimmer/lib/utils/references.ts index 2d8e2b3bb9c..906bca52dc2 100644 --- a/packages/ember-glimmer/lib/utils/references.ts +++ b/packages/ember-glimmer/lib/utils/references.ts @@ -57,19 +57,25 @@ class EmberPathReference { // @abstract get tag() // @abstract value() - get(key) { + get(key?): any { return PropertyReference.create(this, key); } } // @abstract export class CachedReference extends EmberPathReference { + private _lastRevision: any; + private _lastValue: any; + public tag: any; + constructor() { super(); this._lastRevision = null; this._lastValue = null; } + compute() {} + value() { let { tag, _lastRevision, _lastValue } = this; @@ -85,7 +91,8 @@ export class CachedReference extends EmberPathReference { } // @implements PathReference -export class RootReference extends ConstReference { +export class RootReference extends ConstReference { + public children: any; constructor(value) { super(value); this.children = Object.create(null); @@ -107,6 +114,11 @@ let TwoWayFlushDetectionTag; if (EMBER_GLIMMER_DETECT_BACKTRACKING_RERENDER || EMBER_GLIMMER_ALLOW_BACKTRACKING_RERENDER) { TwoWayFlushDetectionTag = class { + public tag: any; + public parent: any; + public key: any; + public ref: any; + constructor(tag, key, ref) { this.tag = tag; this.parent = null; @@ -152,6 +164,9 @@ export class PropertyReference extends CachedReference { } export class RootPropertyReference extends PropertyReference { + private _parentValue: any; + private _propertyKey: any; + constructor(parentValue, propertyKey) { super(); @@ -187,6 +202,10 @@ export class RootPropertyReference extends PropertyReference { } export class NestedPropertyReference extends PropertyReference { + private _parentReference: any; + private _parentObjectTag: any; + private _propertyKey: any; + constructor(parentReference, propertyKey) { super(); @@ -242,6 +261,9 @@ export class NestedPropertyReference extends PropertyReference { } export class UpdatableReference extends EmberPathReference { + public tag: DirtyableTag; + private _value: any; + constructor(value) { super(); @@ -270,6 +292,7 @@ export class UpdatablePrimitiveReference extends UpdatableReference { } export class ConditionalReference extends GlimmerConditionalReference { + public objectTag: UpdatableTag; static create(reference) { if (isConst(reference)) { let value = reference.value(); @@ -303,6 +326,9 @@ export class ConditionalReference extends GlimmerConditionalReference { } export class SimpleHelperReference extends CachedReference { + public helper: any; + public args: any; + static create(helper, args) { if (isConst(args)) { let { positional, named } = args; @@ -351,6 +377,9 @@ export class SimpleHelperReference extends CachedReference { } export class ClassBasedHelperReference extends CachedReference { + public instance: any; + public args: any; + static create(helperClass, vm, args) { let instance = helperClass.create(); vm.newDestroyable(instance); @@ -381,6 +410,9 @@ export class ClassBasedHelperReference extends CachedReference { } export class InternalHelperReference extends CachedReference { + public helper: any; + public args: any; + constructor(helper, args) { super(); @@ -396,7 +428,7 @@ export class InternalHelperReference extends CachedReference { } // @implements PathReference -export class UnboundReference extends ConstReference { +export class UnboundReference extends ConstReference { static create(value) { if (typeof value === 'object' && value !== null) { return new UnboundReference(value); diff --git a/packages/ember-glimmer/lib/utils/string.ts b/packages/ember-glimmer/lib/utils/string.ts index fb98c4d0f60..c3a078edbf3 100644 --- a/packages/ember-glimmer/lib/utils/string.ts +++ b/packages/ember-glimmer/lib/utils/string.ts @@ -5,6 +5,8 @@ import { deprecate } from 'ember-debug'; export class SafeString { + public string: string; + constructor(string) { this.string = string; } diff --git a/packages/ember-glimmer/lib/views/outlet.ts b/packages/ember-glimmer/lib/views/outlet.ts index 4d418a00fd5..0cd4ef80dc3 100644 --- a/packages/ember-glimmer/lib/views/outlet.ts +++ b/packages/ember-glimmer/lib/views/outlet.ts @@ -5,6 +5,9 @@ import { OWNER } from 'ember-utils'; import { run } from 'ember-metal'; class OutletStateReference { + public outletView: any; + public tag: any; + constructor(outletView) { this.outletView = outletView; this.tag = outletView._tag; @@ -31,6 +34,9 @@ class OutletStateReference { // in 3.0. Preferably it is deprecated in the release that // follows the Glimmer release. class OrphanedOutletStateReference extends OutletStateReference { + public root: any; + public name: string; + constructor(root, name) { super(root.outletView); this.root = root; @@ -60,6 +66,10 @@ class OrphanedOutletStateReference extends OutletStateReference { } class ChildOutletStateReference { + public parent: any; + public key: string; + public tag: any; + constructor(parent, key) { this.parent = parent; this.key = key; @@ -76,6 +86,13 @@ class ChildOutletStateReference { } export default class OutletView { + private _environment: any; + public renderer: any; + public owner: any; + public template: any; + public outletState: any; + private _tag: any; + static extend(injections) { return class extends OutletView { static create(options) { diff --git a/packages/ember-metal/lib/index.d.ts b/packages/ember-metal/lib/index.d.ts index c8670d0a639..5f857c05dfd 100644 --- a/packages/ember-metal/lib/index.d.ts +++ b/packages/ember-metal/lib/index.d.ts @@ -1,21 +1,47 @@ -declare module 'ember-metal' { - export const run: { [key: string]: any }; +interface IBackburner { + join(...args: any[]): void; + on(...args: any[]): void; + scheduleOnce(...args: any[]): void; +} +interface IRun { + (...args: any[]): any; + schedule(...args: any[]): void; + later(...args: any[]): void; + join(...args: any[]): void; + backburner: IBackburner +} - export function setHasViews(fn: () => boolean): null; +export const run: IRun; - export function runInTransaction(context: any, methodName: string): any; +export const PROPERTY_DID_CHANGE: symbol; - export function _instrumentStart(name: string, _payload: (_payloadParam: any) => any, _payloadParam: any): () => void; +export const flaggedInstrument: any; - export function get(obj: any, keyName: string): any; +export function setHasViews(fn: () => boolean): null; - export function tagForProperty(object: any, propertyKey: string, _meta?: any): any; +export function runInTransaction(context: any, methodName: string): any; - export function tagFor(object: any, _meta?: any): any; +export function _instrumentStart(name: string, _payload: (_payloadParam: any) => any, _payloadParam: any): () => void; - export function isProxy(value: any): boolean; +export function get(obj: any, keyName: string): any; - export class Cache { - constructor(limit: number, func: (obj: any) => any, key: any, store?: any) - } +export function set(obj: any, keyName: string, value: any, tolerant?: boolean): void; + +export function computed(...args: Array): any; + +export function didRender(object: any, key: string, reference: any): boolean; + +export function isNone(obj: any): boolean; + +export function tagForProperty(object: any, propertyKey: string, _meta?: any): any; + +export function tagFor(object: any, _meta?: any): any; + +export function watchKey(obj: any, keyName: string, meta?: any): void; + +export function isProxy(value: any): boolean; + +export class Cache { + constructor(limit: number, func: (obj: any) => any, key: any, store?: any) + get(obj): any } \ No newline at end of file diff --git a/packages/node-module/lib/index.d.ts b/packages/node-module/lib/index.d.ts new file mode 100644 index 00000000000..52432746b3e --- /dev/null +++ b/packages/node-module/lib/index.d.ts @@ -0,0 +1,3 @@ +export const IS_NODE: boolean; + +export function require(url: string): string; \ No newline at end of file From 340cc6c749b555491a1422ba1ba5132b537956fa Mon Sep 17 00:00:00 2001 From: Steven Footea Date: Tue, 24 Oct 2017 09:55:45 -0600 Subject: [PATCH 12/24] Fix type errors discovered through TypeScript For example, UpdatableTag does not have a public constructor anymore, you must use the static UpdatableTag.create now, which returns the tag in a TagWrapper. --- .../lib/component-managers/abstract.ts | 5 +++- .../lib/component-managers/mount.ts | 3 -- packages/ember-glimmer/lib/environment.ts | 2 +- packages/ember-glimmer/lib/helpers/get.ts | 9 +++--- .../ember-glimmer/lib/helpers/if-unless.ts | 7 +++-- packages/ember-glimmer/lib/renderer.ts | 4 +-- .../lib/syntax/dynamic-component.ts | 2 -- packages/ember-glimmer/lib/syntax/outlet.ts | 9 +++--- packages/ember-glimmer/lib/utils/iterable.ts | 17 ++++++----- .../ember-glimmer/lib/utils/references.ts | 29 +++++++++---------- 10 files changed, 45 insertions(+), 42 deletions(-) diff --git a/packages/ember-glimmer/lib/component-managers/abstract.ts b/packages/ember-glimmer/lib/component-managers/abstract.ts index da6ada534e5..e374fceea0f 100644 --- a/packages/ember-glimmer/lib/component-managers/abstract.ts +++ b/packages/ember-glimmer/lib/component-managers/abstract.ts @@ -1,4 +1,5 @@ import { DEBUG } from 'ember-env-flags'; +import { Destroyable } from '@glimmer/util'; // implements the ComponentManager interface as defined in glimmer: // https://github.com/glimmerjs/glimmer-vm/blob/v0.24.0-beta.4/packages/%40glimmer/runtime/lib/component/interfaces.ts#L21 @@ -56,7 +57,9 @@ export default class AbstractManager { didUpdate(bucket) { } - getDestructor(bucket) { } + getDestructor(bucket): Destroyable { + return bucket.component + } } if (DEBUG) { diff --git a/packages/ember-glimmer/lib/component-managers/mount.ts b/packages/ember-glimmer/lib/component-managers/mount.ts index 0c7f3668ff8..9b1fd4ff4a6 100644 --- a/packages/ember-glimmer/lib/component-managers/mount.ts +++ b/packages/ember-glimmer/lib/component-managers/mount.ts @@ -1,7 +1,6 @@ import { ComponentDefinition } from '@glimmer/runtime'; -import { UNDEFINED_REFERENCE } from '@glimmer/reference'; import { Opaque } from '@glimmer/util'; @@ -34,8 +33,6 @@ class MountManager extends AbstractManager { this._pushEngineToDebugStack(`engine:${name}`, environment) } - dynamicScope.outletState = UNDEFINED_REFERENCE; - let engine: engineType = environment.owner.buildChildEngineInstance(name); engine.boot(); diff --git a/packages/ember-glimmer/lib/environment.ts b/packages/ember-glimmer/lib/environment.ts index a1bef02a7dd..539b9abe2db 100644 --- a/packages/ember-glimmer/lib/environment.ts +++ b/packages/ember-glimmer/lib/environment.ts @@ -203,7 +203,7 @@ export default class Environment extends GlimmerEnvironment { return compilerCache.get(template); } - hasPartial(name, { owner }) { + hasPartial(name: string, { owner }) { return hasPartial(name, owner); } diff --git a/packages/ember-glimmer/lib/helpers/get.ts b/packages/ember-glimmer/lib/helpers/get.ts index 265c14da981..3a10eefccb7 100644 --- a/packages/ember-glimmer/lib/helpers/get.ts +++ b/packages/ember-glimmer/lib/helpers/get.ts @@ -2,6 +2,7 @@ import { set } from 'ember-metal'; import { CachedReference, UPDATE } from '../utils/references'; import { CONSTANT_TAG, + TagWrapper, UpdatableTag, combine, isConst, @@ -69,7 +70,7 @@ class GetHelperReference extends CachedReference { public pathReference: any; public lastPath: any; public innerReference: any; - public innerTag: UpdatableTag; + public innerTag: TagWrapper; public tag: any; static create(sourceReference, pathReference) { @@ -89,7 +90,7 @@ class GetHelperReference extends CachedReference { this.lastPath = null; this.innerReference = NULL_REFERENCE; - let innerTag = this.innerTag = new UpdatableTag(CONSTANT_TAG); + let innerTag = this.innerTag = UpdatableTag.create(CONSTANT_TAG); this.tag = combine([sourceReference.tag, pathReference.tag, innerTag]); } @@ -109,10 +110,10 @@ class GetHelperReference extends CachedReference { innerReference = this.sourceReference.get('' + path); } - innerTag.update(innerReference.tag); + innerTag.inner.update(innerReference.tag); } else { innerReference = NULL_REFERENCE; - innerTag.update(CONSTANT_TAG); + innerTag.inner.update(CONSTANT_TAG); } this.innerReference = innerReference; diff --git a/packages/ember-glimmer/lib/helpers/if-unless.ts b/packages/ember-glimmer/lib/helpers/if-unless.ts index 609eacd74da..84084280619 100644 --- a/packages/ember-glimmer/lib/helpers/if-unless.ts +++ b/packages/ember-glimmer/lib/helpers/if-unless.ts @@ -9,13 +9,14 @@ import { } from '../utils/references'; import { CONSTANT_TAG, + TagWrapper, UpdatableTag, combine, isConst } from '@glimmer/reference'; class ConditionalHelperReference extends CachedReference { - public branchTag: UpdatableTag; + public branchTag: TagWrapper; public tag: any; public cond: any; public truthy: any; @@ -33,7 +34,7 @@ class ConditionalHelperReference extends CachedReference { constructor(cond, truthy, falsy) { super(); - this.branchTag = new UpdatableTag(CONSTANT_TAG); + this.branchTag = UpdatableTag.create(CONSTANT_TAG); this.tag = combine([cond.tag, this.branchTag]); this.cond = cond; @@ -44,7 +45,7 @@ class ConditionalHelperReference extends CachedReference { compute() { let branch = this.cond.value() ? this.truthy : this.falsy; - this.branchTag.update(branch.tag); + this.branchTag.inner.update(branch.tag); return branch.value(); } diff --git a/packages/ember-glimmer/lib/renderer.ts b/packages/ember-glimmer/lib/renderer.ts index 5a081a64133..54b180bebad 100644 --- a/packages/ember-glimmer/lib/renderer.ts +++ b/packages/ember-glimmer/lib/renderer.ts @@ -8,7 +8,7 @@ import { setHasViews, runInTransaction } from 'ember-metal'; -import { CURRENT_TAG, UNDEFINED_REFERENCE } from '@glimmer/reference'; +import { CURRENT_TAG } from '@glimmer/reference'; import { fallbackViewRegistry, getViewElement, @@ -218,7 +218,7 @@ export class Renderer { this._appendDefinition(view, rootDef, target); } - _appendDefinition(root, definition, target, outletStateReference = UNDEFINED_REFERENCE, targetObject = null) { + _appendDefinition(root, definition, target, outletStateReference?, targetObject = null) { let self = new RootReference(definition); let dynamicScope = new DynamicScope(null, outletStateReference, outletStateReference); let rootState = new RootState(root, this._env, this._rootTemplate, self, target, dynamicScope); diff --git a/packages/ember-glimmer/lib/syntax/dynamic-component.ts b/packages/ember-glimmer/lib/syntax/dynamic-component.ts index bdb893d71b8..4969d6b87a0 100644 --- a/packages/ember-glimmer/lib/syntax/dynamic-component.ts +++ b/packages/ember-glimmer/lib/syntax/dynamic-component.ts @@ -1,7 +1,6 @@ import { isComponentDefinition } from '@glimmer/runtime'; -import { UNDEFINED_REFERENCE } from '@glimmer/reference'; import { assert } from 'ember-debug'; import { hashToArgs } from './utils'; @@ -66,6 +65,5 @@ class DynamicComponentReference { } get() { - return UNDEFINED_REFERENCE; } } diff --git a/packages/ember-glimmer/lib/syntax/outlet.ts b/packages/ember-glimmer/lib/syntax/outlet.ts index 6602168d49d..5d4c2bc7a34 100644 --- a/packages/ember-glimmer/lib/syntax/outlet.ts +++ b/packages/ember-glimmer/lib/syntax/outlet.ts @@ -1,6 +1,7 @@ import { UpdatableTag, ConstReference, + TagWrapper, combine } from '@glimmer/reference'; import { OutletComponentDefinition } from '../component-managers/outlet'; @@ -10,7 +11,7 @@ class OutletComponentReference { public parentOutletStateRef: any; public definition: any; public lastState: any; - public outletStateTag: UpdatableTag; + public outletStateTag: TagWrapper; public tag: any; constructor(outletNameRef, parentOutletStateRef) { @@ -18,8 +19,8 @@ class OutletComponentReference { this.parentOutletStateRef = parentOutletStateRef; this.definition = null; this.lastState = null; - let outletStateTag = this.outletStateTag = new UpdatableTag(parentOutletStateRef.tag); - this.tag = combine([outletStateTag.tag, outletNameRef.tag]); + let outletStateTag = this.outletStateTag = UpdatableTag.create(parentOutletStateRef.tag); + this.tag = combine([outletStateTag.inner, outletNameRef.tag]); } value() { @@ -29,7 +30,7 @@ class OutletComponentReference { let outletStateRef = parentOutletStateRef.get('outlets').get(outletName); let newState = this.lastState = outletStateRef.value(); - this.outletStateTag.update(outletStateRef.tag); + this.outletStateTag.inner.update(outletStateRef.tag); definition = revalidate(definition, lastState, newState); diff --git a/packages/ember-glimmer/lib/utils/iterable.ts b/packages/ember-glimmer/lib/utils/iterable.ts index 20343624752..bed9be71401 100644 --- a/packages/ember-glimmer/lib/utils/iterable.ts +++ b/packages/ember-glimmer/lib/utils/iterable.ts @@ -11,9 +11,12 @@ import { import { isEachIn } from '../helpers/each-in'; import { CONSTANT_TAG, + IterationItem, + TagWrapper, UpdatableTag, combine } from '@glimmer/reference'; +import { Opaque } from '@glimmer/util'; const ITERATOR_KEY_GUID = 'be277757-bbbe-4620-9fcb-213ef433cca2'; @@ -150,7 +153,7 @@ class EmptyIterator { return true; } - next() { + next(): IterationItem { throw new Error('Cannot call next() on an empty iterator'); } } @@ -160,14 +163,14 @@ const EMPTY_ITERATOR = new EmptyIterator(); class EachInIterable { public ref: any; public keyFor: (iterable: any) => any; - public valueTag: any; + public valueTag: TagWrapper; public tag: any; constructor(ref, keyFor) { this.ref = ref; this.keyFor = keyFor; - let valueTag = this.valueTag = new UpdatableTag(CONSTANT_TAG); + let valueTag = this.valueTag = UpdatableTag.create(CONSTANT_TAG); this.tag = combine([ref.tag, valueTag]); } @@ -177,7 +180,7 @@ class EachInIterable { let iterable = ref.value(); - valueTag.update(tagFor(iterable)); + valueTag.inner.update(tagFor(iterable)); if (isProxy(iterable)) { iterable = get(iterable, 'content'); @@ -217,14 +220,14 @@ class EachInIterable { class ArrayIterable { public ref: any; public keyFor: (iterable: any) => any; - public valueTag: any; + public valueTag: TagWrapper; public tag: any; constructor(ref, keyFor) { this.ref = ref; this.keyFor = keyFor; - let valueTag = this.valueTag = new UpdatableTag(CONSTANT_TAG); + let valueTag = this.valueTag = UpdatableTag.create(CONSTANT_TAG); this.tag = combine([ref.tag, valueTag]); } @@ -234,7 +237,7 @@ class ArrayIterable { let iterable = ref.value(); - valueTag.update(tagForProperty(iterable, '[]')); + valueTag.inner.update(tagForProperty(iterable, '[]')); if (iterable === null || typeof iterable !== 'object') { return EMPTY_ITERATOR; diff --git a/packages/ember-glimmer/lib/utils/references.ts b/packages/ember-glimmer/lib/utils/references.ts index 906bca52dc2..627a337c779 100644 --- a/packages/ember-glimmer/lib/utils/references.ts +++ b/packages/ember-glimmer/lib/utils/references.ts @@ -1,5 +1,6 @@ import { HAS_NATIVE_WEAKMAP, + Opaque, symbol } from 'ember-utils'; import { @@ -16,13 +17,14 @@ import { ConstReference, DirtyableTag, UpdatableTag, + TagWrapper, + VersionedPathReference, combine, isConst } from '@glimmer/reference'; import { ConditionalReference as GlimmerConditionalReference, - PrimitiveReference, - UNDEFINED_REFERENCE + PrimitiveReference } from '@glimmer/runtime'; import emberToBool from './to-bool'; import { RECOMPUTE_TAG } from '../helper'; @@ -203,14 +205,14 @@ export class RootPropertyReference extends PropertyReference { export class NestedPropertyReference extends PropertyReference { private _parentReference: any; - private _parentObjectTag: any; + private _parentObjectTag: TagWrapper; private _propertyKey: any; constructor(parentReference, propertyKey) { super(); let parentReferenceTag = parentReference.tag; - let parentObjectTag = new UpdatableTag(CONSTANT_TAG); + let parentObjectTag = UpdatableTag.create(CONSTANT_TAG); this._parentReference = parentReference; this._parentObjectTag = parentObjectTag; @@ -230,7 +232,7 @@ export class NestedPropertyReference extends PropertyReference { let parentValue = _parentReference.value(); - _parentObjectTag.update(tagForProperty(parentValue, _propertyKey)); + _parentObjectTag.inner.update(tagForProperty(parentValue, _propertyKey)); let parentValueType = typeof parentValue; @@ -261,13 +263,13 @@ export class NestedPropertyReference extends PropertyReference { } export class UpdatableReference extends EmberPathReference { - public tag: DirtyableTag; + public tag: TagWrapper; private _value: any; constructor(value) { super(); - this.tag = new DirtyableTag(); + this.tag = DirtyableTag.create(); this._value = value; } @@ -279,20 +281,17 @@ export class UpdatableReference extends EmberPathReference { let { _value } = this; if (value !== _value) { - this.tag.dirty(); + this.tag.inner.dirty(); this._value = value; } } } export class UpdatablePrimitiveReference extends UpdatableReference { - get() { - return UNDEFINED_REFERENCE; - } } export class ConditionalReference extends GlimmerConditionalReference { - public objectTag: UpdatableTag; + public objectTag: TagWrapper; static create(reference) { if (isConst(reference)) { let value = reference.value(); @@ -310,16 +309,16 @@ export class ConditionalReference extends GlimmerConditionalReference { constructor(reference) { super(reference); - this.objectTag = new UpdatableTag(CONSTANT_TAG); + this.objectTag = UpdatableTag.create(CONSTANT_TAG); this.tag = combine([reference.tag, this.objectTag]); } toBool(predicate) { if (isProxy(predicate)) { - this.objectTag.update(tagForProperty(predicate, 'isTruthy')); + this.objectTag.inner.update(tagForProperty(predicate, 'isTruthy')); return get(predicate, 'isTruthy'); } else { - this.objectTag.update(tagFor(predicate)); + this.objectTag.inner.update(tagFor(predicate)); return emberToBool(predicate); } } From 42eb72a8038fa5de532e1c098521d8f8a4fcffa4 Mon Sep 17 00:00:00 2001 From: Kris Selden Date: Tue, 24 Oct 2017 14:13:21 -0700 Subject: [PATCH 13/24] fix last type errors --- packages/ember-glimmer/lib/environment.ts | 26 ++++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/packages/ember-glimmer/lib/environment.ts b/packages/ember-glimmer/lib/environment.ts index 539b9abe2db..496543d73d5 100644 --- a/packages/ember-glimmer/lib/environment.ts +++ b/packages/ember-glimmer/lib/environment.ts @@ -17,7 +17,9 @@ import { AttributeManager, isSafeString, compileLayout, - getDynamicVar + getDynamicVar, + DOMTreeConstruction, + PartialDefinition } from '@glimmer/runtime'; import { Opaque @@ -64,6 +66,7 @@ import { GLIMMER_CUSTOM_COMPONENT_MANAGER, EMBER_MODULE_UNIFICATION } from 'ember/features'; +import { DOMChanges } from "@glimmer/runtime/dist/types/lib/dom/helper"; function instrumentationPayload(name) { return { object: `component:${name}` }; @@ -85,9 +88,9 @@ export default class Environment extends GlimmerEnvironment { private _templateCache: Cache; private _compilerCache: Cache; - constructor({ [OWNER]: owner }) { - super(...arguments); - this.owner = owner; + constructor(injections: any) { + super(injections); + let owner = this.owner = injections[OWNER]; this.isInteractive = owner.lookup('-environment:main').isInteractive; // can be removed once https://github.com/tildeio/glimmer/pull/305 lands @@ -167,6 +170,12 @@ export default class Environment extends GlimmerEnvironment { } } + // this gets clobbered by installPlatformSpecificProtocolForURL + // it really should just delegate to a platform specific injection + protocolForURL(s): string { + return s; + } + _resolveLocalLookupName(name, source, owner) { return EMBER_MODULE_UNIFICATION ? `${source}:${name}` : owner._resolveLocalLookupName(name, source); @@ -203,13 +212,14 @@ export default class Environment extends GlimmerEnvironment { return compilerCache.get(template); } - hasPartial(name: string, { owner }) { - return hasPartial(name, owner); + hasPartial(partialName: string, meta: any): boolean { + return hasPartial(name, meta.owner); } - lookupPartial(name, { owner }) { + lookupPartial(PartialName: string, meta: any): PartialDefinition { let partial = { - template: lookupPartial(name, owner) + name, + template: lookupPartial(name, meta.owner) }; if (partial.template) { From 2757794e4a8f80767e228fd2882c254c1b872e68 Mon Sep 17 00:00:00 2001 From: Steven Footea Date: Wed, 25 Oct 2017 13:10:54 -0600 Subject: [PATCH 14/24] Fix ESLint errors --- packages/loader/lib/index.js | 77 +++++++++++++------------ packages/node-module/lib/node-module.js | 1 + 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/packages/loader/lib/index.js b/packages/loader/lib/index.js index 39b3f7fbda6..0ab2aec4cb7 100644 --- a/packages/loader/lib/index.js +++ b/packages/loader/lib/index.js @@ -1,45 +1,8 @@ +/*global process */ var enifed, requireModule, Ember; var mainContext = this; // Used in ember-environment/lib/global.js (function() { - var isNode = typeof window === 'undefined' && - typeof process !== 'undefined' && {}.toString.call(process) === '[object process]'; - - if (!isNode) { - Ember = this.Ember = this.Ember || {}; - } - - if (typeof Ember === 'undefined') { Ember = {}; } - - if (typeof Ember.__loader === 'undefined') { - var registry = {}; - var seen = {}; - - enifed = function(name, deps, callback) { - var value = { }; - - if (!callback) { - value.deps = []; - value.callback = deps; - } else { - value.deps = deps; - value.callback = callback; - } - - registry[name] = value; - }; - - requireModule = function(name) { - return internalRequire(name, null); - }; - - // setup `require` module - requireModule['default'] = requireModule; - - requireModule.has = function registryHas(moduleName) { - return !!registry[moduleName] || !!registry[moduleName + '/index']; - }; - function missingModule(name, referrerName) { if (referrerName) { throw new Error('Could not find module ' + name + ' required by: ' + referrerName); @@ -88,6 +51,44 @@ var mainContext = this; // Used in ember-environment/lib/global.js return exports; } + var isNode = typeof window === 'undefined' && + typeof process !== 'undefined' && {}.toString.call(process) === '[object process]'; + + if (!isNode) { + Ember = this.Ember = this.Ember || {}; + } + + if (typeof Ember === 'undefined') { Ember = {}; } + + if (typeof Ember.__loader === 'undefined') { + var registry = {}; + var seen = {}; + + enifed = function(name, deps, callback) { + var value = { }; + + if (!callback) { + value.deps = []; + value.callback = deps; + } else { + value.deps = deps; + value.callback = callback; + } + + registry[name] = value; + }; + + requireModule = function(name) { + return internalRequire(name, null); + }; + + // setup `require` module + requireModule['default'] = requireModule; + + requireModule.has = function registryHas(moduleName) { + return !!registry[moduleName] || !!registry[moduleName + '/index']; + }; + requireModule._eak_seen = registry; Ember.__loader = { diff --git a/packages/node-module/lib/node-module.js b/packages/node-module/lib/node-module.js index 47dd4ec69df..6989f13316b 100644 --- a/packages/node-module/lib/node-module.js +++ b/packages/node-module/lib/node-module.js @@ -1,3 +1,4 @@ +/*global enifed */ enifed('node-module', ['exports'], function(_exports) { var IS_NODE = typeof module === 'object' && typeof module.require === 'function'; if (IS_NODE) { From 5ee896631714e710ad6922627ca1329c716a496b Mon Sep 17 00:00:00 2001 From: Kris Selden Date: Wed, 25 Oct 2017 12:34:39 -0700 Subject: [PATCH 15/24] fix name issue with partials --- packages/ember-glimmer/lib/environment.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ember-glimmer/lib/environment.ts b/packages/ember-glimmer/lib/environment.ts index 496543d73d5..1c5cf392466 100644 --- a/packages/ember-glimmer/lib/environment.ts +++ b/packages/ember-glimmer/lib/environment.ts @@ -212,11 +212,11 @@ export default class Environment extends GlimmerEnvironment { return compilerCache.get(template); } - hasPartial(partialName: string, meta: any): boolean { + hasPartial(name: string, meta: any): boolean { return hasPartial(name, meta.owner); } - lookupPartial(PartialName: string, meta: any): PartialDefinition { + lookupPartial(name: string, meta: any): PartialDefinition { let partial = { name, template: lookupPartial(name, meta.owner) From 8c68f5b26f50af456af214065d3b411006d420da Mon Sep 17 00:00:00 2001 From: Kris Selden Date: Wed, 25 Oct 2017 17:30:04 -0700 Subject: [PATCH 16/24] more type cleanup --- broccoli/packages.js | 2 - package.json | 3 +- packages/container/tsconfig.json | 19 --- .../lib/component-managers/abstract.ts | 73 +++++++---- .../lib/component-managers/curly.ts | 66 +++++----- .../lib/component-managers/mount.ts | 37 +++--- .../lib/component-managers/outlet.ts | 28 +++-- .../lib/component-managers/render.ts | 32 +++-- .../lib/component-managers/root.ts | 16 +-- packages/ember-glimmer/lib/component.ts | 49 ++++---- .../ember-glimmer/lib/components/checkbox.ts | 4 +- .../ember-glimmer/lib/components/link-to.ts | 33 +++-- .../ember-glimmer/lib/components/text_area.ts | 8 +- .../lib/components/text_field.ts | 10 +- packages/ember-glimmer/lib/environment.ts | 101 ++++++++-------- packages/ember-glimmer/lib/helper.ts | 12 +- packages/ember-glimmer/lib/helpers/-class.ts | 2 +- .../lib/helpers/-normalize-class.ts | 2 +- packages/ember-glimmer/lib/helpers/action.ts | 16 +-- .../ember-glimmer/lib/helpers/component.ts | 16 +-- packages/ember-glimmer/lib/helpers/concat.ts | 2 +- packages/ember-glimmer/lib/helpers/get.ts | 13 +- .../ember-glimmer/lib/helpers/if-unless.ts | 18 +-- packages/ember-glimmer/lib/helpers/loc.ts | 2 +- packages/ember-glimmer/lib/helpers/mut.ts | 2 +- .../ember-glimmer/lib/helpers/query-param.ts | 6 +- .../ember-glimmer/lib/helpers/readonly.ts | 1 - packages/ember-glimmer/lib/helpers/unbound.ts | 2 +- packages/ember-glimmer/lib/index.ts | 6 +- .../ember-glimmer/lib/modifiers/action.ts | 16 +-- packages/ember-glimmer/lib/renderer.ts | 113 +++++++++++------- packages/ember-glimmer/lib/setup-registry.ts | 28 ++--- packages/ember-glimmer/lib/syntax.ts | 16 +-- .../lib/syntax/dynamic-component.ts | 2 +- packages/ember-glimmer/lib/syntax/input.ts | 2 +- packages/ember-glimmer/lib/syntax/mount.ts | 12 +- packages/ember-glimmer/lib/syntax/outlet.ts | 4 +- packages/ember-glimmer/lib/syntax/render.ts | 5 +- packages/ember-glimmer/lib/syntax/utils.ts | 4 +- packages/ember-glimmer/lib/template.ts | 50 ++++++-- .../ember-glimmer/lib/template_registry.ts | 2 +- packages/ember-glimmer/lib/utils/bindings.ts | 14 +-- .../lib/utils/curly-component-state-bucket.ts | 9 +- packages/ember-glimmer/lib/utils/iterable.ts | 32 ++--- .../ember-glimmer/lib/utils/process-args.ts | 4 +- .../ember-glimmer/lib/utils/references.ts | 51 ++++---- packages/ember-glimmer/lib/utils/string.ts | 6 +- packages/ember-glimmer/lib/utils/to-bool.ts | 2 +- packages/ember-glimmer/lib/views/outlet.ts | 60 ++++++---- yarn.lock | 74 +++++++++++- 50 files changed, 628 insertions(+), 459 deletions(-) delete mode 100644 packages/container/tsconfig.json diff --git a/broccoli/packages.js b/broccoli/packages.js index 5d560f7a334..2e5f2c46cc8 100644 --- a/broccoli/packages.js +++ b/broccoli/packages.js @@ -5,9 +5,7 @@ const path = require('path'); const Rollup = require('broccoli-rollup'); const Funnel = require('broccoli-funnel'); const filterTypeScript = require('broccoli-typescript-compiler').filterTypeScript; -const TypeScriptPlugin = require('broccoli-typescript-compiler').TypeScriptPlugin; const BroccoliDebug = require('broccoli-debug'); -const MergeTrees = require('broccoli-merge-trees'); const findLib = require('./find-lib'); const funnelLib = require('./funnel-lib'); const { VERSION } = require('./version'); diff --git a/package.json b/package.json index 433ebc6a0a1..2c9026fff89 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,8 @@ "resolve": "^1.3.3", "rsvp": "^4.7.0", "simple-dom": "^0.3.0", - "simple-html-tokenizer": "^0.4.1" + "simple-html-tokenizer": "^0.4.1", + "tslint": "^5.8.0" }, "devDependencies": { "aws-sdk": "^2.46.0", diff --git a/packages/container/tsconfig.json b/packages/container/tsconfig.json deleted file mode 100644 index 67cf7ff1ab1..00000000000 --- a/packages/container/tsconfig.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "compilerOptions": { - "target": "es2015", - "module": "es2015", - "moduleResolution": "node", - "baseUrl": ".", - "paths": { - "*": ["packages/*/lib/index"] - } - }, - "include": [ - "container/**/*.ts" - ], - "exclude": [ - "node_modules", - "packages", - "**/*.d.ts" - ] -} diff --git a/packages/ember-glimmer/lib/component-managers/abstract.ts b/packages/ember-glimmer/lib/component-managers/abstract.ts index e374fceea0f..52578116d1f 100644 --- a/packages/ember-glimmer/lib/component-managers/abstract.ts +++ b/packages/ember-glimmer/lib/component-managers/abstract.ts @@ -1,10 +1,25 @@ +import { ProgramSymbolTable } from '@glimmer/interfaces'; +import { Tag, VersionedPathReference } from '@glimmer/reference'; +import { + Bounds, + CompiledDynamicProgram, + CompiledDynamicTemplate, + ComponentDefinition, + ComponentManager, + DynamicScope, + ElementOperations, + Environment, + PreparedArguments, +} from '@glimmer/runtime'; +import { IArguments } from '@glimmer/runtime/dist/types/lib/vm/arguments'; +import { Destroyable, Opaque, Option } from '@glimmer/util'; import { DEBUG } from 'ember-env-flags'; -import { Destroyable } from '@glimmer/util'; // implements the ComponentManager interface as defined in glimmer: +// tslint:disable-next-line:max-line-length // https://github.com/glimmerjs/glimmer-vm/blob/v0.24.0-beta.4/packages/%40glimmer/runtime/lib/component/interfaces.ts#L21 -export default class AbstractManager { +export default abstract class AbstractManager implements ComponentManager { public debugStack: any; public _pushToDebugStack: (name: string, environment: any) => void; public _pushEngineToDebugStack: (name: string, environment: any) => void; @@ -13,53 +28,61 @@ export default class AbstractManager { this.debugStack = undefined; } - prepareArgs(definition, args): any | null { + prepareArgs(definition: ComponentDefinition, args: IArguments): Option { return null; } // must be implemented by inheritors, inheritors should also // call `this._pushToDebugStack` to ensure the rerendering // assertion messages are properly maintained - create(env, definition, args, dynamicScope, caller, hasBlock) { - if (DEBUG) { - throw new Error('AbstractManager#create must be implemented.'); - } - } - layoutFor(definition, bucket, env) { - if (DEBUG) { - throw new Error('AbstractManager#create must be implemented.'); - } + abstract create( + env: Environment, + definition: ComponentDefinition, + args: IArguments, + dynamicScope: DynamicScope, + caller: VersionedPathReference, + hasDefaultBlock: boolean): T; + abstract layoutFor( + definition: ComponentDefinition, component: T, env: Environment): CompiledDynamicTemplate; + abstract getSelf(component: T): VersionedPathReference; + + didCreateElement(component: T, element: Element, operations: ElementOperations): void { + // noop } - getSelf(bucket) { return bucket; } - - didCreateElement(bucket, element, operations) { } - // inheritors should also call `this.debugStack.pop()` to // ensure the rerendering assertion messages are properly // maintained - didRenderLayout(bucket, bounds) { } + didRenderLayout(component: T, bounds: Bounds): void { + // noop + } - didCreate(bucket) { } + didCreate(bucket: T): void { + // noop + } - getTag(bucket) { return null; } + getTag(bucket: T): Option { return null; } // inheritors should also call `this._pushToDebugStack` // to ensure the rerendering assertion messages are // properly maintained - update(bucket, dynamicScope?) { } + update(bucket: T, dynamicScope: DynamicScope): void { + // noop + } // inheritors should also call `this.debugStack.pop()` to // ensure the rerendering assertion messages are properly // maintained - didUpdateLayout(bucket, bounds) { } - - didUpdate(bucket) { } + didUpdateLayout(bucket: T, bounds: Bounds): void { + // noop + } - getDestructor(bucket): Destroyable { - return bucket.component + didUpdate(bucket: T): void { + // noop } + + abstract getDestructor(bucket: T): Option; } if (DEBUG) { diff --git a/packages/ember-glimmer/lib/component-managers/curly.ts b/packages/ember-glimmer/lib/component-managers/curly.ts index 8d6573a1054..901883a5a58 100644 --- a/packages/ember-glimmer/lib/component-managers/curly.ts +++ b/packages/ember-glimmer/lib/component-managers/curly.ts @@ -1,39 +1,39 @@ -import { - Opaque, - OWNER, - assign -} from 'ember-utils'; import { combineTagged } from '@glimmer/reference'; import { + ComponentDefinition, PrimitiveReference, - ComponentDefinition } from '@glimmer/runtime'; +import { privatize as P } from 'container'; import { - assert + assert, } from 'ember-debug'; import { DEBUG } from 'ember-env-flags'; import { - ROOT_REF, + _instrumentStart, + get, +} from 'ember-metal'; +import { + assign, + Opaque, + OWNER, +} from 'ember-utils'; +import { setViewElement } from 'ember-views'; +import { + BOUNDS, DIRTY_TAG, - IS_DISPATCHING_ATTRS, HAS_BLOCK, - BOUNDS + IS_DISPATCHING_ATTRS, + ROOT_REF, } from '../component'; import { AttributeBinding, ClassNameBinding, - IsVisibleBinding + IsVisibleBinding, } from '../utils/bindings'; -import { - get, - _instrumentStart -} from 'ember-metal'; -import { processComponentArgs } from '../utils/process-args'; -import { setViewElement } from 'ember-views'; -import { privatize as P } from 'container'; -import AbstractManager from './abstract'; import ComponentStateBucket from '../utils/curly-component-state-bucket'; +import { processComponentArgs } from '../utils/process-args'; import { PropertyReference } from '../utils/references'; +import AbstractManager from './abstract'; const DEFAULT_LAYOUT = P`template:components/-default`; @@ -48,12 +48,12 @@ function aliasIdToElementId(args, props) { // what has already been applied. This is essentially refining the concatenated // properties applying right to left. function applyAttributeBindings(element, attributeBindings, component, operations) { - let seen: Array = []; + let seen: string[] = []; let i = attributeBindings.length - 1; while (i !== -1) { let binding = attributeBindings[i]; - let parsed: Array = AttributeBinding.parse(binding); + let parsed: string[] = AttributeBinding.parse(binding); let attribute = parsed[1]; if (seen.indexOf(attribute) === -1) { @@ -111,7 +111,7 @@ export class PositionalArgumentReference { } value() { - return this._references.map(reference => reference.value()); + return this._references.map((reference) => reference.value()); } get(key) { @@ -119,7 +119,7 @@ export class PositionalArgumentReference { } } -export default class CurlyComponentManager extends AbstractManager { +export default class CurlyComponentManager extends AbstractManager { prepareArgs(definition, args) { let componentPositionalParamsDefinition = definition.ComponentClass.class.positionalParams; @@ -152,10 +152,10 @@ export default class CurlyComponentManager extends AbstractManager { let positionalParamsToNamed; if (componentHasRestStylePositionalParams) { positionalParamsToNamed = { - [componentPositionalParamsDefinition]: new PositionalArgumentReference(positional) + [componentPositionalParamsDefinition]: new PositionalArgumentReference(positional), }; positional = []; - } else if (componentHasPositionalParams){ + } else if (componentHasPositionalParams) { positionalParamsToNamed = {}; let length = Math.min(positional.length, componentPositionalParamsDefinition.length); for (let i = 0; i < length; i++) { @@ -171,7 +171,7 @@ export default class CurlyComponentManager extends AbstractManager { create(environment, definition, args, dynamicScope, callerSelfRef, hasBlock) { if (DEBUG) { - this._pushToDebugStack(`component:${definition.name}`, environment) + this._pushToDebugStack(`component:${definition.name}`, environment); } let parentView = dynamicScope.view; @@ -274,13 +274,13 @@ export default class CurlyComponentManager extends AbstractManager { } if (classNames && classNames.length) { - classNames.forEach(name => { + classNames.forEach((name) => { operations.addStaticAttribute(element, 'class', name); }); } if (classNameBindings && classNameBindings.length) { - classNameBindings.forEach(binding => { + classNameBindings.forEach((binding) => { ClassNameBinding.install(element, component, binding, operations); }); } @@ -313,11 +313,11 @@ export default class CurlyComponentManager extends AbstractManager { } } - update(bucket) { + update(bucket: ComponentStateBucket) { let { component, args, argsRevision, environment } = bucket; if (DEBUG) { - this._pushToDebugStack(component._debugContainerKey, environment) + this._pushToDebugStack(component._debugContainerKey, environment); } bucket.finalizer = _instrumentStart('render.component', rerenderInstrumentDetails, component); @@ -341,7 +341,7 @@ export default class CurlyComponentManager extends AbstractManager { } } - didUpdateLayout(bucket) { + didUpdateLayout(bucket: ComponentStateBucket) { bucket.finalize(); if (DEBUG) { @@ -356,7 +356,7 @@ export default class CurlyComponentManager extends AbstractManager { } } - getDestructor(stateBucket) { + getDestructor(stateBucket: ComponentStateBucket) { return stateBucket; } } @@ -381,7 +381,7 @@ export function validatePositionalParameters(named, positional, positionalParams assert( `You cannot specify both a positional param (at position ${i}) and the hash argument \`${name}\`.`, - !named.has(name) + !named.has(name), ); } } diff --git a/packages/ember-glimmer/lib/component-managers/mount.ts b/packages/ember-glimmer/lib/component-managers/mount.ts index 9b1fd4ff4a6..6b6f52c35a6 100644 --- a/packages/ember-glimmer/lib/component-managers/mount.ts +++ b/packages/ember-glimmer/lib/component-managers/mount.ts @@ -1,43 +1,38 @@ import { - ComponentDefinition + ComponentDefinition, } from '@glimmer/runtime'; import { - Opaque + Opaque, } from '@glimmer/util'; import { DEBUG } from 'ember-env-flags'; -import { RootReference } from '../utils/references'; -import { OutletLayoutCompiler } from './outlet'; -import AbstractManager from './abstract'; import { generateControllerFactory } from 'ember-routing'; import { EMBER_ENGINES_MOUNT_PARAMS } from 'ember/features'; +import { RootReference } from '../utils/references'; +import AbstractManager from './abstract'; +import { OutletLayoutCompiler } from './outlet'; -//TODO: remove these stubbed interfaces when better typing is in place -interface engineType { +// TODO: remove these stubbed interfaces when better typing is in place +interface EngineType { boot(): void; -}; +} -interface bucketType { +interface EngineBucket { modelReference?: any; - engine: engineType; -}; - - -class MountManager extends AbstractManager { - prepareArgs(definition, args) { - return null; - } + engine: EngineType; +} +class MountManager extends AbstractManager { create(environment, { name }, args, dynamicScope) { if (DEBUG) { - this._pushEngineToDebugStack(`engine:${name}`, environment) + this._pushEngineToDebugStack(`engine:${name}`, environment); } - let engine: engineType = environment.owner.buildChildEngineInstance(name); + let engine: EngineType = environment.owner.buildChildEngineInstance(name); engine.boot(); - let bucket: bucketType = { engine }; + let bucket: EngineBucket = { engine }; if (EMBER_ENGINES_MOUNT_PARAMS) { bucket.modelReference = args.named.get('model'); @@ -73,7 +68,7 @@ class MountManager extends AbstractManager { didRenderLayout() { if (DEBUG) { - this.debugStack.pop() + this.debugStack.pop(); } } diff --git a/packages/ember-glimmer/lib/component-managers/outlet.ts b/packages/ember-glimmer/lib/component-managers/outlet.ts index cf5da00f177..688b6be51b2 100644 --- a/packages/ember-glimmer/lib/component-managers/outlet.ts +++ b/packages/ember-glimmer/lib/component-managers/outlet.ts @@ -1,9 +1,13 @@ -import { generateGuid, guidFor } from 'ember-utils'; +import { Option } from '@glimmer/interfaces/dist/types'; import { - ComponentDefinition + ComponentDefinition, + DynamicScope, } from '@glimmer/runtime'; +import { Destroyable } from '@glimmer/util/dist/types'; import { DEBUG } from 'ember-env-flags'; +import { Environment } from 'ember-glimmer'; import { _instrumentStart } from 'ember-metal'; +import { generateGuid, guidFor } from 'ember-utils'; import { RootReference } from '../utils/references'; import AbstractManager from './abstract'; @@ -11,7 +15,11 @@ function instrumentationPayload({ render: { name, outlet } }) { return { object: `${name}:${outlet}` }; } -function NOOP() {} +function NOOP() {/**/} + +interface OutletDynamicScope extends DynamicScope { + outletState: any; +} class StateBucket { public outletState: any; @@ -33,13 +41,14 @@ class StateBucket { } } -class OutletComponentManager extends AbstractManager { - create(environment, definition, args, dynamicScope) { +class OutletComponentManager extends AbstractManager { + create(environment: Environment, definition: OutletComponentDefinition, args, dynamicScope: OutletDynamicScope) { if (DEBUG) { this._pushToDebugStack(`template:${definition.template.meta.moduleName}`, environment); } - let outletStateReference = dynamicScope.outletState = dynamicScope.outletState.get('outlets').get(definition.outletName); + let outletStateReference = dynamicScope.outletState = + dynamicScope.outletState.get('outlets').get(definition.outletName); let outletState = outletStateReference.value(); return new StateBucket(outletState); } @@ -59,6 +68,10 @@ class OutletComponentManager extends AbstractManager { this.debugStack.pop(); } } + + getDestructor(bucket: StateBucket): Option { + return null; + } } const MANAGER = new OutletComponentManager(); @@ -78,8 +91,7 @@ class TopLevelOutletComponentManager extends OutletComponentManager { const TOP_LEVEL_MANAGER = new TopLevelOutletComponentManager(); - -export class TopLevelOutletComponentDefinition extends ComponentDefinition { +export class TopLevelOutletComponentDefinition extends ComponentDefinition { public template: any; constructor(instance) { super('outlet', TOP_LEVEL_MANAGER, instance); diff --git a/packages/ember-glimmer/lib/component-managers/render.ts b/packages/ember-glimmer/lib/component-managers/render.ts index f89a06fbd79..7d18834b193 100644 --- a/packages/ember-glimmer/lib/component-managers/render.ts +++ b/packages/ember-glimmer/lib/component-managers/render.ts @@ -1,14 +1,22 @@ import { - ComponentDefinition + VersionedPathReference, +} from '@glimmer/reference'; +import { + ComponentDefinition, } from '@glimmer/runtime'; +import { IArguments } from '@glimmer/runtime/dist/types/lib/vm/arguments'; +import { Destroyable } from '@glimmer/util'; + import { assert } from 'ember-debug'; import { DEBUG } from 'ember-env-flags'; -import { RootReference } from '../utils/references'; import { generateController, generateControllerFactory } from 'ember-routing'; -import { OutletLayoutCompiler } from './outlet'; +import Environment from '../environment'; +import { DynamicScope } from '../renderer'; +import { RootReference } from '../utils/references'; import AbstractManager from './abstract'; +import { OutletLayoutCompiler } from './outlet'; -export class AbstractRenderManager extends AbstractManager { +export abstract class AbstractRenderManager extends AbstractManager { layoutFor(definition, bucket, env) { return env.getCompiledBlock(OutletLayoutCompiler, definition.template); } @@ -24,13 +32,17 @@ if (DEBUG) { }; } +export interface RenderState { + controller: Destroyable; +} + class SingletonRenderManager extends AbstractRenderManager { - create(environment, definition, args, dynamicScope) { - let { name, env } = definition; + create(env: Environment, definition: ComponentDefinition, args: IArguments, dynamicScope: DynamicScope) { + let { name } = definition; let controller = env.owner.lookup(`controller:${name}`) || generateController(env.owner, name); if (DEBUG) { - this._pushToDebugStack(`controller:${name} (with the render helper)`, environment); + this._pushToDebugStack(`controller:${name} (with the render helper)`, env); } if (dynamicScope.rootOutletState) { @@ -39,6 +51,10 @@ class SingletonRenderManager extends AbstractRenderManager { return { controller }; } + + getDestructor() { + return null; + } } export const SINGLETON_RENDER_MANAGER = new SingletonRenderManager(); @@ -77,7 +93,7 @@ export const NON_SINGLETON_RENDER_MANAGER = new NonSingletonRenderManager(); export class RenderDefinition extends ComponentDefinition { public name: string; public template: any; - public env: any; + public env: Environment; constructor(name, template, env, manager) { super('render', manager, null); diff --git a/packages/ember-glimmer/lib/component-managers/root.ts b/packages/ember-glimmer/lib/component-managers/root.ts index 0ecba2a3314..24d6f484c0b 100644 --- a/packages/ember-glimmer/lib/component-managers/root.ts +++ b/packages/ember-glimmer/lib/component-managers/root.ts @@ -1,17 +1,17 @@ import { - ComponentDefinition + ComponentDefinition, } from '@glimmer/runtime'; import { - _instrumentStart -} from 'ember-metal'; -import { - assert + assert, } from 'ember-debug'; import { DEBUG } from 'ember-env-flags'; +import { + _instrumentStart, +} from 'ember-metal'; import ComponentStateBucket from '../utils/curly-component-state-bucket'; import CurlyComponentManager, { initialRenderInstrumentDetails, - processComponentInitializationAssertions + processComponentInitializationAssertions, } from './curly'; class RootComponentManager extends CurlyComponentManager { @@ -19,7 +19,7 @@ class RootComponentManager extends CurlyComponentManager { let component = definition.ComponentClass.create(); if (DEBUG) { - this._pushToDebugStack(component._debugContainerKey, environment) + this._pushToDebugStack(component._debugContainerKey, environment); } let finalizer = _instrumentStart('render.component', initialRenderInstrumentDetails, component); @@ -57,7 +57,7 @@ export class RootComponentDefinition extends ComponentDefinition { class: instance.constructor, create() { return instance; - } + }, }); this.template = undefined; this.args = undefined; diff --git a/packages/ember-glimmer/lib/component.ts b/packages/ember-glimmer/lib/component.ts index 87be2b1ed7d..5a803347758 100644 --- a/packages/ember-glimmer/lib/component.ts +++ b/packages/ember-glimmer/lib/component.ts @@ -1,25 +1,25 @@ -import { symbol, getOwner, NAME_KEY } from 'ember-utils'; -import { - CoreView, - ClassNamesSupport, - ChildViewsSupport, - ViewStateSupport, - ViewMixin, - ActionSupport, - getViewElement -} from 'ember-views'; -import { TargetActionSupport } from 'ember-runtime'; +import { DirtyableTag } from '@glimmer/reference'; +import { readDOMAttr } from '@glimmer/runtime'; import { assert, - deprecate + deprecate, } from 'ember-debug'; import { get, PROPERTY_DID_CHANGE, } from 'ember-metal'; -import { UPDATE, RootReference } from './utils/references'; -import { DirtyableTag } from '@glimmer/reference'; -import { readDOMAttr } from '@glimmer/runtime'; +import { TargetActionSupport } from 'ember-runtime'; +import { getOwner, NAME_KEY, symbol } from 'ember-utils'; +import { + ActionSupport, + ChildViewsSupport, + ClassNamesSupport, + CoreView, + getViewElement, + ViewMixin, + ViewStateSupport, +} from 'ember-views'; +import { RootReference, UPDATE } from './utils/references'; export const DIRTY_TAG = symbol('DIRTY_TAG'); export const ARGS = symbol('ARGS'); @@ -109,7 +109,6 @@ export const BOUNDS = symbol('BOUNDS'); elements. This is consistent with the same requirement in web components. - ## HTML Tag The default HTML tag name used for a component's DOM representation is `div`. @@ -130,7 +129,6 @@ export const BOUNDS = symbol('BOUNDS'); ``` - ## HTML `class` Attribute The HTML `class` attribute of a component's tag can be set by providing a @@ -315,7 +313,6 @@ export const BOUNDS = symbol('BOUNDS'); [EmberObject](/api/classes/Ember.Object.html) documentation for more information about concatenated properties. - ## HTML Attributes The HTML attribute section of a component's tag can be set by providing an @@ -438,7 +435,6 @@ export const BOUNDS = symbol('BOUNDS'); `attributeBindings` is a concatenated property. See [EmberObject](/api/classes/Ember.Object.html) documentation for more information about concatenated properties. - ## Layouts See [Ember.Templates.helpers.yield](/api/classes/Ember.Templates.helpers.html#method_yield) @@ -472,14 +468,12 @@ export const BOUNDS = symbol('BOUNDS'); ``` - ## Responding to Browser Events Components can respond to user-initiated events in one of three ways: method implementation, through an event manager, and through `{{action}}` helper use in their template or layout. - ### Method Implementation Components can respond to user-initiated events by implementing a method that @@ -497,12 +491,10 @@ export const BOUNDS = symbol('BOUNDS'); }); ``` - ### `{{action}}` Helper See [Ember.Templates.helpers.action](/api/classes/Ember.Templates.helpers.html#method_action). - ### Event Names All of the event handling approaches described above respond to the same set @@ -589,8 +581,8 @@ const Component = CoreView.extend( { id: 'ember-views.component.defaultLayout', until: '3.0.0', - url: 'https://emberjs.com/deprecations/v2.x/#toc_ember-component-defaultlayout' - } + url: 'https://emberjs.com/deprecations/v2.x/#toc_ember-component-defaultlayout', + }, ); this.layout = this.defaultLayout; @@ -676,7 +668,7 @@ const Component = CoreView.extend( readDOMAttr(name) { let element = getViewElement(this); return readDOMAttr(element, name); - } + }, /** The WAI-ARIA role of the control represented by this view. For example, a @@ -754,7 +746,6 @@ const Component = CoreView.extend( @since 1.13.0 */ - /** Called when the attributes passed into the component have been updated. Called both during the initial render of a container and during a rerender. @@ -921,14 +912,14 @@ const Component = CoreView.extend( @default null @public */ - } + }, ); Component[NAME_KEY] = 'Ember.Component'; Component.reopenClass({ isComponentFactory: true, - positionalParams: [] + positionalParams: [], }); export default Component; diff --git a/packages/ember-glimmer/lib/components/checkbox.ts b/packages/ember-glimmer/lib/components/checkbox.ts index 0cc8bb66e69..e8c82835fb4 100644 --- a/packages/ember-glimmer/lib/components/checkbox.ts +++ b/packages/ember-glimmer/lib/components/checkbox.ts @@ -44,7 +44,7 @@ export default EmberComponent.extend({ 'name', 'autofocus', 'required', - 'form' + 'form', ], type: 'checkbox', @@ -58,5 +58,5 @@ export default EmberComponent.extend({ change() { set(this, 'checked', this.$().prop('checked')); - } + }, }); diff --git a/packages/ember-glimmer/lib/components/link-to.ts b/packages/ember-glimmer/lib/components/link-to.ts index 03ec18a30ef..f2c5254ae8a 100644 --- a/packages/ember-glimmer/lib/components/link-to.ts +++ b/packages/ember-glimmer/lib/components/link-to.ts @@ -313,23 +313,25 @@ import Logger from 'ember-console'; import { assert, deprecate } from 'ember-debug'; +import { DEBUG } from 'ember-env-flags'; import { - get, computed, - flaggedInstrument + flaggedInstrument, + get, } from 'ember-metal'; import { + ControllerMixin, deprecatingAlias, inject, - ControllerMixin } from 'ember-runtime'; import { isSimpleClick } from 'ember-views'; -import layout from '../templates/link-to'; import EmberComponent, { HAS_BLOCK } from '../component'; -import { DEBUG } from 'ember-env-flags'; +import layout from '../templates/link-to'; + /** @module @ember/routing */ + /** `LinkComponent` renders an element whose `click` event triggers a transition of the application's instance of `Router` to @@ -433,7 +435,6 @@ const LinkComponent = EmberComponent.extend({ @private **/ disabledClass: 'disabled', - _isDisabled: false, /** Determines whether the `LinkComponent` will trigger routing via @@ -524,6 +525,7 @@ const LinkComponent = EmberComponent.extend({ */ init() { this._super(...arguments); + this._isDisabled = false; // Map desired event name to invoke function let eventName = get(this, 'eventName'); @@ -548,7 +550,7 @@ const LinkComponent = EmberComponent.extend({ if (value !== undefined) { this.set('_isDisabled', value); } return value ? get(this, 'disabledClass') : false; - } + }, }), _isActive(routerState) { @@ -651,6 +653,7 @@ const LinkComponent = EmberComponent.extend({ if (get(this, '_isDisabled')) { return false; } if (get(this, 'loading')) { + // tslint:disable-next-line:max-line-length Logger.warn('This link-to is in an inactive loading state because at least one of its parameters presently has a null/undefined value, or the provided route name is invalid.'); return false; } @@ -666,9 +669,10 @@ const LinkComponent = EmberComponent.extend({ let payload = { queryParams, - routeName: qualifiedRouteName + routeName: qualifiedRouteName, }; + // tslint:disable-next-line:max-line-length flaggedInstrument('interaction.link-to', payload, this._generateTransition(payload, qualifiedRouteName, models, queryParams, shouldReplace)); }, @@ -681,7 +685,8 @@ const LinkComponent = EmberComponent.extend({ queryParams: null, - qualifiedRouteName: computed('targetRouteName', '_routing.currentState', function computeLinkToComponentQualifiedRouteName() { + qualifiedRouteName: computed('targetRouteName', '_routing.currentState', + function computeLinkToComponentQualifiedRouteName() { let params = get(this, 'params'); let paramsLength = params.length; let lastParam = params[paramsLength - 1]; @@ -746,6 +751,7 @@ const LinkComponent = EmberComponent.extend({ try { routing.generateURL(qualifiedRouteName, models, queryParams); } catch (e) { + // tslint:disable-next-line:max-line-length assert('You attempted to define a `{{link-to "' + qualifiedRouteName + '"}}` but did not pass the parameters required for generating its dynamic segments. ' + e.message); } } @@ -781,9 +787,10 @@ const LinkComponent = EmberComponent.extend({ while (ControllerMixin.detect(value)) { deprecate( 'Providing `{{link-to}}` with a param that is wrapped in a controller is deprecated. ' + - (this.parentView ? 'Please update `' + this.parentView + '` to use `{{link-to "post" someController.model}}` instead.' : ''), + (this.parentView ? 'Please update `' + this.parentView + + '` to use `{{link-to "post" someController.model}}` instead.' : ''), false, - { id: 'ember-routing-views.controller-wrapped-param', until: '3.0.0' } + { id: 'ember-routing-views.controller-wrapped-param', until: '3.0.0' }, ); value = value.get('model'); } @@ -847,13 +854,13 @@ const LinkComponent = EmberComponent.extend({ } else { this.set('models', []); } - } + }, }); LinkComponent.toString = () => 'LinkComponent'; LinkComponent.reopenClass({ - positionalParams: 'params' + positionalParams: 'params', }); export default LinkComponent; diff --git a/packages/ember-glimmer/lib/components/text_area.ts b/packages/ember-glimmer/lib/components/text_area.ts index e4cc0359caa..b6888239c2a 100644 --- a/packages/ember-glimmer/lib/components/text_area.ts +++ b/packages/ember-glimmer/lib/components/text_area.ts @@ -1,8 +1,8 @@ /** @module @ember/component */ -import Component from '../component'; import { TextSupport } from 'ember-views'; +import Component from '../component'; import layout from '../templates/empty'; /** @@ -217,7 +217,7 @@ import layout from '../templates/empty'; export default Component.extend(TextSupport, { classNames: ['ember-text-area'], - layout: layout, + layout, tagName: 'textarea', attributeBindings: [ @@ -229,8 +229,8 @@ export default Component.extend(TextSupport, { 'wrap', 'lang', 'dir', - 'value' + 'value', ], rows: null, - cols: null + cols: null, }); diff --git a/packages/ember-glimmer/lib/components/text_field.ts b/packages/ember-glimmer/lib/components/text_field.ts index 51528c94ab8..ef4fa752d4b 100644 --- a/packages/ember-glimmer/lib/components/text_field.ts +++ b/packages/ember-glimmer/lib/components/text_field.ts @@ -1,11 +1,11 @@ /** @module @ember/component */ -import { computed } from 'ember-metal'; import { environment } from 'ember-environment'; +import { computed } from 'ember-metal'; +import { TextSupport } from 'ember-views'; import Component from '../component'; import layout from '../templates/empty'; -import { TextSupport } from 'ember-views'; const inputTypes = Object.create(null); function canSetTypeOfInput(type) { @@ -76,7 +76,7 @@ export default Component.extend(TextSupport, { 'size', 'step', 'value', - 'width' + 'width', ], /** @@ -111,7 +111,7 @@ export default Component.extend(TextSupport, { } return type; - } + }, }), /** @@ -154,5 +154,5 @@ export default Component.extend(TextSupport, { @since 1.4.0 @public */ - max: null + max: null, }); diff --git a/packages/ember-glimmer/lib/environment.ts b/packages/ember-glimmer/lib/environment.ts index 1c5cf392466..cfebd674cbd 100644 --- a/packages/ember-glimmer/lib/environment.ts +++ b/packages/ember-glimmer/lib/environment.ts @@ -1,72 +1,73 @@ /// -import { guidFor, OWNER } from 'ember-utils'; -import { Cache, _instrumentStart } from 'ember-metal'; -import { assert, warn } from 'ember-debug'; -import { DEBUG } from 'ember-env-flags'; -import { - lookupPartial, - hasPartial, - lookupComponent, - constructStyleDeprecationMessage -} from 'ember-views'; import { - Reference + Reference, } from '@glimmer/reference'; import { - Environment as GlimmerEnvironment, AttributeManager, - isSafeString, compileLayout, - getDynamicVar, DOMTreeConstruction, - PartialDefinition + Environment as GlimmerEnvironment, + getDynamicVar, + isSafeString, + PartialDefinition, } from '@glimmer/runtime'; import { - Opaque + Destroyable, Opaque, } from '@glimmer/util'; +import { assert, warn } from 'ember-debug'; +import { DEBUG } from 'ember-env-flags'; +import { _instrumentStart, Cache } from 'ember-metal'; +import { guidFor, OWNER } from 'ember-utils'; import { - CurlyComponentDefinition + constructStyleDeprecationMessage, + hasPartial, + lookupComponent, + lookupPartial, +} from 'ember-views'; +import { + CurlyComponentDefinition, } from './component-managers/curly'; import { - populateMacros + populateMacros, } from './syntax'; +import DebugStack from './utils/debug-stack'; import createIterable from './utils/iterable'; import { + ClassBasedHelperReference, ConditionalReference, SimpleHelperReference, - ClassBasedHelperReference } from './utils/references'; -import DebugStack from './utils/debug-stack'; -import { - inlineIf, - inlineUnless -} from './helpers/if-unless'; +import { default as classHelper } from './helpers/-class'; +import { default as htmlSafeHelper } from './helpers/-html-safe'; +import { default as inputTypeHelper } from './helpers/-input-type'; +import { default as normalizeClassHelper } from './helpers/-normalize-class'; import { default as action } from './helpers/action'; import { default as componentHelper } from './helpers/component'; import { default as concat } from './helpers/concat'; +import { default as eachIn } from './helpers/each-in'; import { default as get } from './helpers/get'; import { default as hash } from './helpers/hash'; +import { + inlineIf, + inlineUnless, +} from './helpers/if-unless'; import { default as loc } from './helpers/loc'; import { default as log } from './helpers/log'; import { default as mut } from './helpers/mut'; +import { default as queryParams } from './helpers/query-param'; import { default as readonly } from './helpers/readonly'; import { default as unbound } from './helpers/unbound'; -import { default as classHelper } from './helpers/-class'; -import { default as inputTypeHelper } from './helpers/-input-type'; -import { default as queryParams } from './helpers/query-param'; -import { default as eachIn } from './helpers/each-in'; -import { default as normalizeClassHelper } from './helpers/-normalize-class'; -import { default as htmlSafeHelper } from './helpers/-html-safe'; -import installPlatformSpecificProtocolForURL from './protocol-for-url'; import { default as ActionModifierManager } from './modifiers/action'; +import installPlatformSpecificProtocolForURL from './protocol-for-url'; +import { DOMChanges } from '@glimmer/runtime/dist/types/lib/dom/helper'; import { + EMBER_MODULE_UNIFICATION, GLIMMER_CUSTOM_COMPONENT_MANAGER, - EMBER_MODULE_UNIFICATION } from 'ember/features'; -import { DOMChanges } from "@glimmer/runtime/dist/types/lib/dom/helper"; +import { Container } from './template'; function instrumentationPayload(name) { return { object: `component:${name}` }; @@ -77,12 +78,16 @@ export default class Environment extends GlimmerEnvironment { return new this(options); } - public owner: any; + public owner: Container; public isInteractive: boolean; - public destroyedComponents: Array; - public builtInModifiers: any; - public builtInHelpers: any; - public debugStack: any; + public destroyedComponents: Destroyable[]; + public builtInModifiers: { + [name: string]: any; + }; + public builtInHelpers: { + [name: string]: any; + }; + public debugStack: typeof DebugStack; public inTransaction: boolean; private _definitionCache: Cache; private _templateCache: Cache; @@ -100,7 +105,7 @@ export default class Environment extends GlimmerEnvironment { this._definitionCache = new Cache(2000, ({ name, source, owner }) => { let { component: componentFactory, layout } = lookupComponent(owner, name, { source }); - let customManager = undefined; + let customManager; if (componentFactory || layout) { if (GLIMMER_CUSTOM_COMPONENT_MANAGER) { @@ -130,22 +135,22 @@ export default class Environment extends GlimmerEnvironment { } }, ({ Template, owner }) => guidFor(owner) + '|' + Template.id); - this._compilerCache = new Cache(10, Compiler => { + this._compilerCache = new Cache(10, (Compiler) => { return new Cache(2000, (template) => { let compilable = new Compiler(template); return compileLayout(compilable, this); - }, (template)=> { + }, (template) => { let owner = template.meta.owner; return guidFor(owner) + '|' + template.id; }); - }, Compiler => Compiler.id); + }, (Compiler) => Compiler.id); this.builtInModifiers = { - action: new ActionModifierManager() + action: new ActionModifierManager(), }; this.builtInHelpers = { - if: inlineIf, + 'if': inlineIf, action, concat, get, @@ -156,17 +161,17 @@ export default class Environment extends GlimmerEnvironment { 'query-params': queryParams, readonly, unbound, - unless: inlineUnless, + 'unless': inlineUnless, '-class': classHelper, '-each-in': eachIn, '-input-type': inputTypeHelper, '-normalize-class': normalizeClassHelper, '-html-safe': htmlSafeHelper, - '-get-dynamic-var': getDynamicVar + '-get-dynamic-var': getDynamicVar, }; if (DEBUG) { - this.debugStack = new DebugStack() + this.debugStack = new DebugStack(); } } @@ -219,7 +224,7 @@ export default class Environment extends GlimmerEnvironment { lookupPartial(name: string, meta: any): PartialDefinition { let partial = { name, - template: lookupPartial(name, meta.owner) + template: lookupPartial(name, meta.owner), }; if (partial.template) { diff --git a/packages/ember-glimmer/lib/helper.ts b/packages/ember-glimmer/lib/helper.ts index 1bc71d8be09..3ff1594ae31 100644 --- a/packages/ember-glimmer/lib/helper.ts +++ b/packages/ember-glimmer/lib/helper.ts @@ -2,9 +2,9 @@ @module @ember/component */ -import { symbol } from 'ember-utils'; -import { FrameworkObject } from 'ember-runtime'; import { DirtyableTag } from '@glimmer/reference'; +import { FrameworkObject } from 'ember-runtime'; +import { symbol } from 'ember-utils'; export const RECOMPUTE_TAG = symbol('RECOMPUTE_TAG'); @@ -50,7 +50,7 @@ export const RECOMPUTE_TAG = symbol('RECOMPUTE_TAG'); @public @since 1.13.0 */ -var Helper = FrameworkObject.extend({ +let Helper = FrameworkObject.extend({ isHelperInstance: true, init() { @@ -87,7 +87,7 @@ var Helper = FrameworkObject.extend({ */ recompute() { this[RECOMPUTE_TAG].dirty(); - } + }, /** Override this function when writing a class-based helper. @@ -101,7 +101,7 @@ var Helper = FrameworkObject.extend({ }); Helper.reopenClass({ - isHelperFactory: true + isHelperFactory: true, }); /** @@ -129,7 +129,7 @@ Helper.reopenClass({ export function helper(helperFn) { return { isHelperInstance: true, - compute: helperFn + compute: helperFn, }; } diff --git a/packages/ember-glimmer/lib/helpers/-class.ts b/packages/ember-glimmer/lib/helpers/-class.ts index 2d780793490..6dc8f5d3705 100644 --- a/packages/ember-glimmer/lib/helpers/-class.ts +++ b/packages/ember-glimmer/lib/helpers/-class.ts @@ -1,5 +1,5 @@ -import { InternalHelperReference } from '../utils/references'; import { String as StringUtils } from 'ember-runtime'; +import { InternalHelperReference } from '../utils/references'; function classHelper({ positional }) { let path = positional.at(0); diff --git a/packages/ember-glimmer/lib/helpers/-normalize-class.ts b/packages/ember-glimmer/lib/helpers/-normalize-class.ts index 4d347ac658a..beaef34c08a 100644 --- a/packages/ember-glimmer/lib/helpers/-normalize-class.ts +++ b/packages/ember-glimmer/lib/helpers/-normalize-class.ts @@ -1,5 +1,5 @@ -import { InternalHelperReference } from '../utils/references'; import { String as StringUtils } from 'ember-runtime'; +import { InternalHelperReference } from '../utils/references'; function normalizeClass({ positional, named }) { let classNameParts = positional.at(0).value().split('.'); diff --git a/packages/ember-glimmer/lib/helpers/action.ts b/packages/ember-glimmer/lib/helpers/action.ts index 12214373c1c..d9d54ee3e7e 100644 --- a/packages/ember-glimmer/lib/helpers/action.ts +++ b/packages/ember-glimmer/lib/helpers/action.ts @@ -1,17 +1,17 @@ /** @module ember */ -import { symbol } from 'ember-utils'; +import { isConst } from '@glimmer/reference'; +import { assert } from 'ember-debug'; +import { DEBUG } from 'ember-env-flags'; import { - run, - get, flaggedInstrument, - isNone + get, + isNone, + run, } from 'ember-metal'; +import { symbol } from 'ember-utils'; import { UnboundReference } from '../utils/references'; -import { isConst } from '@glimmer/reference'; -import { assert } from 'ember-debug'; -import { DEBUG } from 'ember-env-flags'; export const INVOKE = symbol('INVOKE'); export const ACTION = symbol('ACTION'); @@ -309,7 +309,7 @@ function makeArgsProcessor(valuePathRef, actionArgsRef) { if (actionArgsRef.length > 0) { mergeArgs = function(args) { - return actionArgsRef.map(ref => ref.value()).concat(args); + return actionArgsRef.map((ref) => ref.value()).concat(args); }; } diff --git a/packages/ember-glimmer/lib/helpers/component.ts b/packages/ember-glimmer/lib/helpers/component.ts index e161660efa1..40b2f18ea62 100644 --- a/packages/ember-glimmer/lib/helpers/component.ts +++ b/packages/ember-glimmer/lib/helpers/component.ts @@ -1,16 +1,16 @@ /** @module ember */ +import { + isComponentDefinition, +} from '@glimmer/runtime'; +import { assert } from 'ember-debug'; import { assign } from 'ember-utils'; -import { CachedReference } from '../utils/references'; import { CurlyComponentDefinition, - validatePositionalParameters + validatePositionalParameters, } from '../component-managers/curly'; -import { - isComponentDefinition -} from '@glimmer/runtime'; -import { assert } from 'ember-debug'; +import { CachedReference } from '../utils/references'; /** The `{{component}}` helper lets you add instances of `Component` to a @@ -193,7 +193,7 @@ export class ClosureComponentReference extends CachedReference { } else { assert( `You cannot create a component from ${nameOrDef} using the {{component}} helper`, - nameOrDef + nameOrDef, ); return null; } @@ -213,7 +213,7 @@ function createCurriedDefinition(definition, args) { definition.name, definition.ComponentClass, definition.template, - curriedArgs + curriedArgs, ); } diff --git a/packages/ember-glimmer/lib/helpers/concat.ts b/packages/ember-glimmer/lib/helpers/concat.ts index b4db9711e54..d9a289ef8cf 100644 --- a/packages/ember-glimmer/lib/helpers/concat.ts +++ b/packages/ember-glimmer/lib/helpers/concat.ts @@ -1,5 +1,5 @@ -import { InternalHelperReference } from '../utils/references'; import { normalizeTextValue } from '@glimmer/runtime'; +import { InternalHelperReference } from '../utils/references'; /** @module ember diff --git a/packages/ember-glimmer/lib/helpers/get.ts b/packages/ember-glimmer/lib/helpers/get.ts index 3a10eefccb7..e897e9998cb 100644 --- a/packages/ember-glimmer/lib/helpers/get.ts +++ b/packages/ember-glimmer/lib/helpers/get.ts @@ -1,17 +1,16 @@ -import { set } from 'ember-metal'; -import { CachedReference, UPDATE } from '../utils/references'; import { + combine, CONSTANT_TAG, + isConst, + referenceFromParts, TagWrapper, UpdatableTag, - combine, - isConst, - referenceFromParts } from '@glimmer/reference'; import { - NULL_REFERENCE + NULL_REFERENCE, } from '@glimmer/runtime'; - +import { set } from 'ember-metal'; +import { CachedReference, UPDATE } from '../utils/references'; /** @module ember diff --git a/packages/ember-glimmer/lib/helpers/if-unless.ts b/packages/ember-glimmer/lib/helpers/if-unless.ts index 84084280619..668d7db0c66 100644 --- a/packages/ember-glimmer/lib/helpers/if-unless.ts +++ b/packages/ember-glimmer/lib/helpers/if-unless.ts @@ -2,18 +2,18 @@ @module ember */ -import { assert } from 'ember-debug'; -import { - CachedReference, - ConditionalReference -} from '../utils/references'; import { + combine, CONSTANT_TAG, + isConst, TagWrapper, UpdatableTag, - combine, - isConst } from '@glimmer/reference'; +import { assert } from 'ember-debug'; +import { + CachedReference, + ConditionalReference, +} from '../utils/references'; class ConditionalHelperReference extends CachedReference { public branchTag: TagWrapper; @@ -137,7 +137,7 @@ export function inlineIf(vm, { positional }) { assert( 'The inline form of the `if` helper expects two or three arguments, e.g. ' + '`{{if trialExpired "Expired" expiryDate}}`.', - positional.length === 3 || positional.length === 2 + positional.length === 3 || positional.length === 2, ); return ConditionalHelperReference.create(positional.at(0), positional.at(1), positional.at(2)); } @@ -166,7 +166,7 @@ export function inlineUnless(vm, { positional }) { assert( 'The inline form of the `unless` helper expects two or three arguments, e.g. ' + '`{{unless isFirstLogin "Welcome back!"}}`.', - positional.length === 3 || positional.length === 2 + positional.length === 3 || positional.length === 2, ); return ConditionalHelperReference.create(positional.at(0), positional.at(2), positional.at(1)); } diff --git a/packages/ember-glimmer/lib/helpers/loc.ts b/packages/ember-glimmer/lib/helpers/loc.ts index 3e1a1d75064..b6d9d9ac66a 100644 --- a/packages/ember-glimmer/lib/helpers/loc.ts +++ b/packages/ember-glimmer/lib/helpers/loc.ts @@ -2,8 +2,8 @@ /** @module ember */ -import { InternalHelperReference } from '../utils/references'; import { String as StringUtils } from 'ember-runtime'; +import { InternalHelperReference } from '../utils/references'; /** Calls [loc](/api/classes/Ember.String.html#method_loc) with the diff --git a/packages/ember-glimmer/lib/helpers/mut.ts b/packages/ember-glimmer/lib/helpers/mut.ts index 945374b212b..d490a779cc3 100644 --- a/packages/ember-glimmer/lib/helpers/mut.ts +++ b/packages/ember-glimmer/lib/helpers/mut.ts @@ -1,8 +1,8 @@ /** @module ember */ -import { symbol } from 'ember-utils'; import { assert } from 'ember-debug'; +import { symbol } from 'ember-utils'; import { UPDATE } from '../utils/references'; import { INVOKE } from './action'; diff --git a/packages/ember-glimmer/lib/helpers/query-param.ts b/packages/ember-glimmer/lib/helpers/query-param.ts index 19f2971f65a..9c8af51f491 100644 --- a/packages/ember-glimmer/lib/helpers/query-param.ts +++ b/packages/ember-glimmer/lib/helpers/query-param.ts @@ -1,10 +1,10 @@ /** @module ember */ -import { assign } from 'ember-utils'; -import { InternalHelperReference } from '../utils/references'; import { assert } from 'ember-debug'; import { QueryParams } from 'ember-routing'; +import { assign } from 'ember-utils'; +import { InternalHelperReference } from '../utils/references'; /** This is a helper to be used in conjunction with the link-to helper. @@ -26,7 +26,7 @@ function queryParams({ positional, named }) { assert('The `query-params` helper only accepts hash parameters, e.g. (query-params queryParamPropertyName=\'foo\') as opposed to just (query-params \'foo\')', positional.value().length === 0); return QueryParams.create({ - values: assign({}, named.value()) + values: assign({}, named.value()), }); } diff --git a/packages/ember-glimmer/lib/helpers/readonly.ts b/packages/ember-glimmer/lib/helpers/readonly.ts index 9d5092bf126..031ecf194ea 100644 --- a/packages/ember-glimmer/lib/helpers/readonly.ts +++ b/packages/ember-glimmer/lib/helpers/readonly.ts @@ -4,7 +4,6 @@ import { UPDATE } from '../utils/references'; import { unMut } from './mut'; - /** The `readonly` helper let's you specify that a binding is one-way only, instead of two-way. diff --git a/packages/ember-glimmer/lib/helpers/unbound.ts b/packages/ember-glimmer/lib/helpers/unbound.ts index 3c2543e2068..30cb8f8fe06 100644 --- a/packages/ember-glimmer/lib/helpers/unbound.ts +++ b/packages/ember-glimmer/lib/helpers/unbound.ts @@ -36,7 +36,7 @@ import { UnboundReference } from '../utils/references'; export default function(vm, args) { assert( 'unbound helper cannot be called with multiple params or hash params', - args.positional.length === 1 && args.named.length === 0 + args.positional.length === 1 && args.named.length === 0, ); return UnboundReference.create(args.positional.at(0).value()); diff --git a/packages/ember-glimmer/lib/index.ts b/packages/ember-glimmer/lib/index.ts index 4622e8d06dd..e6484511aa7 100644 --- a/packages/ember-glimmer/lib/index.ts +++ b/packages/ember-glimmer/lib/index.ts @@ -274,20 +274,20 @@ export { escapeExpression, htmlSafe, isHTMLSafe, - getSafeString as _getSafeString + getSafeString as _getSafeString, } from './utils/string'; export { Renderer, InertRenderer, InteractiveRenderer, - _resetRenderers + _resetRenderers, } from './renderer'; export { getTemplate, setTemplate, hasTemplate, getTemplates, - setTemplates + setTemplates, } from './template_registry'; export { setupEngineRegistry, setupApplicationRegistry } from './setup-registry'; export { DOMChanges, NodeDOMTreeConstruction, DOMTreeConstruction } from './dom'; diff --git a/packages/ember-glimmer/lib/modifiers/action.ts b/packages/ember-glimmer/lib/modifiers/action.ts index 3e590226cf1..c276607dfac 100644 --- a/packages/ember-glimmer/lib/modifiers/action.ts +++ b/packages/ember-glimmer/lib/modifiers/action.ts @@ -1,9 +1,9 @@ -import { uuid } from 'ember-utils'; -import { run, flaggedInstrument } from 'ember-metal'; import { assert } from 'ember-debug'; +import { flaggedInstrument, run } from 'ember-metal'; +import { uuid } from 'ember-utils'; import { + ActionManager, isSimpleClick, - ActionManager } from 'ember-views'; import { INVOKE } from '../helpers/action'; @@ -49,7 +49,7 @@ export let ActionHelper = { let { actionId } = actionState; delete ActionManager.registeredActions[actionId]; - } + }, }; export class ActionState { @@ -126,7 +126,7 @@ export class ActionState { let payload = { args, target, - name: null + name: null, }; if (typeof actionName[INVOKE] === 'function') { flaggedInstrument('interaction.ember-action', payload, () => { @@ -148,7 +148,7 @@ export class ActionState { } else { assert( `The action '${actionName}' did not exist on ${target}`, - typeof target[actionName] === 'function' + typeof target[actionName] === 'function', ); flaggedInstrument('interaction.ember-action', payload, () => { target[actionName].apply(target, args); @@ -184,7 +184,7 @@ export default class ActionModifierManager { '{{action}} helper which did not resolve to an action name (a ' + 'string). Perhaps you meant to use a quoted actionName? (e.g. ' + '{{action "' + actionLabel + '"}}).', - typeof actionName === 'string' || typeof actionName === 'function' + typeof actionName === 'string' || typeof actionName === 'function', ); } } @@ -205,7 +205,7 @@ export default class ActionModifierManager { named, positional, implicitTarget, - dom + dom, ); } diff --git a/packages/ember-glimmer/lib/renderer.ts b/packages/ember-glimmer/lib/renderer.ts index 54b180bebad..30b33ba1428 100644 --- a/packages/ember-glimmer/lib/renderer.ts +++ b/packages/ember-glimmer/lib/renderer.ts @@ -2,49 +2,55 @@ interface FreeformObject { [key: string]: any; } -import { RootReference } from './utils/references'; +import { Simple } from '@glimmer/interfaces'; +import { CURRENT_TAG, VersionedPathReference } from '@glimmer/reference'; +import { IteratorResult } from '@glimmer/runtime'; +import { Opaque } from '@glimmer/util'; +import { assert } from 'ember-debug'; +import { Environment } from 'ember-glimmer'; import { run, + runInTransaction, setHasViews, - runInTransaction } from 'ember-metal'; -import { CURRENT_TAG } from '@glimmer/reference'; import { fallbackViewRegistry, getViewElement, + getViewId, setViewElement, - getViewId } from 'ember-views'; import { BOUNDS } from './component'; -import { RootComponentDefinition } from './component-managers/root'; import { TopLevelOutletComponentDefinition } from './component-managers/outlet'; -import { assert } from 'ember-debug'; +import { RootComponentDefinition } from './component-managers/root'; +import { OwnedTemplate } from './template'; +import { RootReference } from './utils/references'; +import OutletView, { OutletState, OutletStateReference } from './views/outlet'; -const { backburner } = run; +import { ComponentDefinition, RenderResult } from '@glimmer/runtime'; -class DynamicScope { - private view: any - private outletState: any - private rootOutletState: any +const { backburner } = run; - constructor(view, outletState, rootOutletState) { - this.view = view; - this.outletState = outletState; - this.rootOutletState = rootOutletState; +export class DynamicScope { + constructor( + public view: Opaque, + public outletState?: VersionedPathReference, + public rootOutletState?: OutletStateReference) { } child() { return new DynamicScope( - this.view, this.outletState, this.rootOutletState + this.view, this.outletState, this.rootOutletState, ); } get(key) { + // tslint:disable-next-line:max-line-length assert(`Using \`-get-dynamic-scope\` is only supported for \`outletState\` (you used \`${key}\`).`, key === 'outletState'); return this.outletState; } set(key, value) { + // tslint:disable-next-line:max-line-length assert(`Using \`-with-dynamic-scope\` is only supported for \`outletState\` (you used \`${key}\`).`, key === 'outletState'); this.outletState = value; return value; @@ -52,18 +58,26 @@ class DynamicScope { } class RootState { - public id: any - public env: any - public root: any - public result: any - public shouldReflush: boolean - public destroyed: boolean - private _removing: boolean - public options: any - public render: any - - constructor(root, env, template, self, parentElement, dynamicScope) { - assert(`You cannot render \`${self.value()}\` without a template.`, template); + public id: string; + public env: Environment; + public root: Opaque; + public result: RenderResult; + public shouldReflush: boolean; + public destroyed: boolean; + public options: { + alwaysRevalidate: boolean; + }; + public render: () => void; + private _removing: boolean; + + constructor( + root: Opaque, + env: Environment, + template: OwnedTemplate, + self: VersionedPathReference, + parentElement: Simple.Element, + dynamicScope: DynamicScope) { + assert(`You cannot render \`${self.value()}\` without a template.`, template !== undefined); this.id = getViewId(root); this.env = env; @@ -74,12 +88,12 @@ class RootState { this._removing = false; let options = this.options = { - alwaysRevalidate: false + alwaysRevalidate: false, }; this.render = () => { let iterator = template.render(self, parentElement, dynamicScope); - let iteratorResult; + let iteratorResult: IteratorResult; do { iteratorResult = iterator.next(); @@ -157,7 +171,7 @@ function loopBegin() { } } -function K() {} +function K() { /* noop */ } let loops = 0; function loopEnd(current, next) { @@ -180,15 +194,17 @@ backburner.on('begin', loopBegin); backburner.on('end', loopEnd); export class Renderer { - private _env: any - private _rootTemplate: any - private _viewRegistry: any - private _destinedForDOM: any - private _destroyed: boolean - private _roots: Array - private _lastRevision: any - private _isRenderingRoots: boolean - private _removedRoots: Array + private _env: Environment; + private _rootTemplate: any; + private _viewRegistry: { + [viewId: string]: Opaque, + }; + private _destinedForDOM: boolean; + private _destroyed: boolean; + private _roots: RootState[]; + private _lastRevision: number; + private _isRenderingRoots: boolean; + private _removedRoots: RootState[]; constructor(env, rootTemplate, _viewRegistry = fallbackViewRegistry, destinedForDOM = false) { this._env = env; @@ -204,7 +220,7 @@ export class Renderer { // renderer HOOKS - appendOutletView(view, target) { + appendOutletView(view: OutletView, target: Simple.Element) { let definition = new TopLevelOutletComponentDefinition(view); let outletStateReference = view.toReference(); let targetObject = view.outletState.render.controller; @@ -212,13 +228,18 @@ export class Renderer { this._appendDefinition(view, definition, target, outletStateReference, targetObject); } - appendTo(view, target) { + appendTo(view: Opaque, target: Simple.Element) { let rootDef = new RootComponentDefinition(view); this._appendDefinition(view, rootDef, target); } - _appendDefinition(root, definition, target, outletStateReference?, targetObject = null) { + _appendDefinition( + root: Opaque, + definition: ComponentDefinition, + target: Simple.Element, + outletStateReference?: OutletStateReference, + targetObject: Opaque = null) { let self = new RootReference(definition); let dynamicScope = new DynamicScope(null, outletStateReference, outletStateReference); let rootState = new RootState(root, this._env, this._rootTemplate, self, target, dynamicScope); @@ -226,11 +247,11 @@ export class Renderer { this._renderRoot(rootState); } - rerender(view) { + rerender() { this._scheduleRevalidate(); } - register(view) { + register(view: Opaque) { let id = getViewId(view); assert('Attempted to register a view with an id already in use: ' + id, !this._viewRegistry[id]); this._viewRegistry[id] = view; @@ -300,7 +321,7 @@ export class Renderer { return this._env.getAppendOperations().createElement(tagName); } - _renderRoot(root) { + _renderRoot(root: RootState) { let { _roots: roots } = this; roots.push(root); diff --git a/packages/ember-glimmer/lib/setup-registry.ts b/packages/ember-glimmer/lib/setup-registry.ts index 1bc494c48e6..8d947a8f24e 100644 --- a/packages/ember-glimmer/lib/setup-registry.ts +++ b/packages/ember-glimmer/lib/setup-registry.ts @@ -1,21 +1,21 @@ -import { environment } from 'ember-environment'; import { privatize as P } from 'container'; -import { InteractiveRenderer, InertRenderer } from './renderer'; +import { environment } from 'ember-environment'; +import Component from './component'; +import Checkbox from './components/checkbox'; +import LinkToComponent from './components/link-to'; +import TextArea from './components/text_area'; +import TextField from './components/text_field'; import { DOMChanges, DOMTreeConstruction, - NodeDOMTreeConstruction + NodeDOMTreeConstruction, } from './dom'; -import OutletView from './views/outlet'; -import TextField from './components/text_field'; -import TextArea from './components/text_area'; -import Checkbox from './components/checkbox'; -import LinkToComponent from './components/link-to'; -import Component from './component'; +import Environment from './environment'; +import { InertRenderer, InteractiveRenderer } from './renderer'; import ComponentTemplate from './templates/component'; -import RootTemplate from './templates/root'; import OutletTemplate from './templates/outlet'; -import Environment from './environment'; +import RootTemplate from './templates/root'; +import OutletView from './views/outlet'; export function setupApplicationRegistry(registry) { registry.injection('service:-glimmer-environment', 'appendOperations', 'service:-dom-tree-construction'); @@ -34,14 +34,14 @@ export function setupApplicationRegistry(registry) { registry.register('service:-dom-changes', { create({ document }) { return new DOMChanges(document); - } + }, }); registry.register('service:-dom-tree-construction', { create({ document }) { - var Implementation = environment.hasDOM ? DOMTreeConstruction : NodeDOMTreeConstruction; + let Implementation = environment.hasDOM ? DOMTreeConstruction : NodeDOMTreeConstruction; return new Implementation(document); - } + }, }); } diff --git a/packages/ember-glimmer/lib/syntax.ts b/packages/ember-glimmer/lib/syntax.ts index 1f0238cea3d..2cb8b1a1e9b 100644 --- a/packages/ember-glimmer/lib/syntax.ts +++ b/packages/ember-glimmer/lib/syntax.ts @@ -1,15 +1,15 @@ -import { renderMacro } from './syntax/render'; -import { outletMacro } from './syntax/outlet'; -import { mountMacro } from './syntax/mount'; +import { assert } from 'ember-debug'; +import { textAreaMacro } from './syntax/-text-area'; import { blockComponentMacro, - inlineComponentMacro + inlineComponentMacro, } from './syntax/dynamic-component'; -import { wrapComponentClassAttribute } from './utils/bindings'; import { inputMacro } from './syntax/input'; -import { textAreaMacro } from './syntax/-text-area'; +import { mountMacro } from './syntax/mount'; +import { outletMacro } from './syntax/outlet'; +import { renderMacro } from './syntax/render'; import { hashToArgs } from './syntax/utils'; -import { assert } from 'ember-debug'; +import { wrapComponentClassAttribute } from './utils/bindings'; function refineInlineSyntax(name, params, hash, builder) { assert(`You attempted to overwrite the built-in helper "${name}" which is not allowed. Please rename the helper.`, !(builder.env.builtInHelpers[name] && builder.env.owner.hasRegistration(`helper:${name}`))); @@ -53,7 +53,7 @@ function refineBlockSyntax(name, params, hash, _default, inverse, builder) { return false; } -export const experimentalMacros: Array = []; +export const experimentalMacros: any[] = []; // This is a private API to allow for experimental macros // to be created in user space. Registering a macro should diff --git a/packages/ember-glimmer/lib/syntax/dynamic-component.ts b/packages/ember-glimmer/lib/syntax/dynamic-component.ts index 4969d6b87a0..ef1a30ea6b1 100644 --- a/packages/ember-glimmer/lib/syntax/dynamic-component.ts +++ b/packages/ember-glimmer/lib/syntax/dynamic-component.ts @@ -1,5 +1,5 @@ import { - isComponentDefinition + isComponentDefinition, } from '@glimmer/runtime'; import { assert } from 'ember-debug'; import { hashToArgs } from './utils'; diff --git a/packages/ember-glimmer/lib/syntax/input.ts b/packages/ember-glimmer/lib/syntax/input.ts index 5e21514f545..80313a3a613 100644 --- a/packages/ember-glimmer/lib/syntax/input.ts +++ b/packages/ember-glimmer/lib/syntax/input.ts @@ -171,7 +171,7 @@ export function inputMacro(name, params, hash, builder) { assert( '{{input type=\'checkbox\'}} does not support setting `value=someBooleanValue`; ' + 'you must use `checked=someBooleanValue` instead.', - valueIndex === -1 + valueIndex === -1, ); wrapComponentClassAttribute(hash); return buildSyntax('-checkbox', params, hash, builder); diff --git a/packages/ember-glimmer/lib/syntax/mount.ts b/packages/ember-glimmer/lib/syntax/mount.ts index 6080ea415aa..ef9d28448fb 100644 --- a/packages/ember-glimmer/lib/syntax/mount.ts +++ b/packages/ember-glimmer/lib/syntax/mount.ts @@ -4,8 +4,8 @@ import { assert } from 'ember-debug'; import { DEBUG } from 'ember-env-flags'; import { EMBER_ENGINES_MOUNT_PARAMS } from 'ember/features'; -import { hashToArgs } from './utils'; import { MountDefinition } from '../component-managers/mount'; +import { hashToArgs } from './utils'; function dynamicEngineFor(vm, args, meta) { let env = vm.env; @@ -59,12 +59,12 @@ export function mountMacro(name, params, hash, builder) { if (EMBER_ENGINES_MOUNT_PARAMS) { assert( 'You can only pass a single positional argument to the {{mount}} helper, e.g. {{mount "chat-engine"}}.', - params.length === 1 + params.length === 1, ); } else { assert( 'You can only pass a single argument to the {{mount}} helper, e.g. {{mount "chat-engine"}}.', - params.length === 1 && hash === null + params.length === 1 && hash === null, ); } @@ -91,7 +91,7 @@ class DynamicEngineReference { } value() { - let { env, nameRef, /*meta*/ } = this; + let { env, nameRef /*meta*/ } = this; let nameOrDef = nameRef.value(); if (typeof nameOrDef === 'string') { @@ -101,7 +101,7 @@ class DynamicEngineReference { assert( `You used \`{{mount '${nameOrDef}'}}\`, but the engine '${nameOrDef}' can not be found.`, - env.owner.hasRegistration(`engine:${nameOrDef}`) + env.owner.hasRegistration(`engine:${nameOrDef}`), ); if (!env.owner.hasRegistration(`engine:${nameOrDef}`)) { @@ -115,7 +115,7 @@ class DynamicEngineReference { } else { assert( `Invalid engine name '${nameOrDef}' specified, engine name must be either a string, null or undefined.`, - nameOrDef === null || nameOrDef === undefined + nameOrDef === null || nameOrDef === undefined, ); return null; diff --git a/packages/ember-glimmer/lib/syntax/outlet.ts b/packages/ember-glimmer/lib/syntax/outlet.ts index 5d4c2bc7a34..e99a726ef0e 100644 --- a/packages/ember-glimmer/lib/syntax/outlet.ts +++ b/packages/ember-glimmer/lib/syntax/outlet.ts @@ -1,8 +1,8 @@ import { - UpdatableTag, + combine, ConstReference, TagWrapper, - combine + UpdatableTag, } from '@glimmer/reference'; import { OutletComponentDefinition } from '../component-managers/outlet'; diff --git a/packages/ember-glimmer/lib/syntax/render.ts b/packages/ember-glimmer/lib/syntax/render.ts index 4d645329bdb..87cbef380f7 100644 --- a/packages/ember-glimmer/lib/syntax/render.ts +++ b/packages/ember-glimmer/lib/syntax/render.ts @@ -4,12 +4,12 @@ import { ConstReference, isConst } from '@glimmer/reference'; import { assert } from 'ember-debug'; -import { hashToArgs } from './utils'; import { + NON_SINGLETON_RENDER_MANAGER, RenderDefinition, SINGLETON_RENDER_MANAGER, - NON_SINGLETON_RENDER_MANAGER } from '../component-managers/render'; +import { hashToArgs } from './utils'; function makeComponentDefinition(vm, args) { let env = vm.env; @@ -45,7 +45,6 @@ function makeComponentDefinition(vm, args) { } } - /** Calling ``{{render}}`` from within a template will insert another template that matches the provided name. The inserted template will diff --git a/packages/ember-glimmer/lib/syntax/utils.ts b/packages/ember-glimmer/lib/syntax/utils.ts index cb3558966d2..000e36a65cb 100644 --- a/packages/ember-glimmer/lib/syntax/utils.ts +++ b/packages/ember-glimmer/lib/syntax/utils.ts @@ -1,5 +1,5 @@ export function hashToArgs(hash) { - if (hash === null) return null; - let names = hash[0].map(key => `@${key}`); + if (hash === null) { return null; } + let names = hash[0].map((key) => `@${key}`); return [names, hash[1]]; } diff --git a/packages/ember-glimmer/lib/template.ts b/packages/ember-glimmer/lib/template.ts index 96a57abb822..d58fda7906f 100644 --- a/packages/ember-glimmer/lib/template.ts +++ b/packages/ember-glimmer/lib/template.ts @@ -1,14 +1,44 @@ +import { + Template, + templateFactory, + TemplateFactory, +} from '@glimmer/runtime'; import { OWNER } from 'ember-utils'; -import { templateFactory } from '@glimmer/runtime'; -export default function template(json) { - const factory = templateFactory(json); - - return { - id: factory.id, - meta: factory.meta, - create(props) { - return factory.create(props.env, { owner: props[OWNER] }); - } +export interface Container { + lookup(name: string): T; +} + +export type OwnedTemplate = Template<{ + moduleName: string; + owner: Container; +}>; + +class WrappedTemplateFactory { + id: string; + meta: { + moduleName: string; }; + constructor(public factory: TemplateFactory<{ + moduleName: string; + }, { + owner: Container; + }>) { + this.id = factory.id; + this.meta = factory.meta; + } + + create(props: any): OwnedTemplate { + let owner = props[OWNER]; + return this.factory.create(props.env, { owner }); + } +} + +export default function template(json) { + const factory = templateFactory<{ + moduleName: string; + }, { + owner: Container; + }>(json); + return new WrappedTemplateFactory(factory); } diff --git a/packages/ember-glimmer/lib/template_registry.ts b/packages/ember-glimmer/lib/template_registry.ts index c39f8472a98..1cb5fdfbc3a 100644 --- a/packages/ember-glimmer/lib/template_registry.ts +++ b/packages/ember-glimmer/lib/template_registry.ts @@ -17,7 +17,7 @@ export function getTemplate(name) { } } -export function hasTemplate(name):boolean { +export function hasTemplate(name): boolean { return TEMPLATES.hasOwnProperty(name); } diff --git a/packages/ember-glimmer/lib/utils/bindings.ts b/packages/ember-glimmer/lib/utils/bindings.ts index 695e8714fcb..dd34df2e8cc 100644 --- a/packages/ember-glimmer/lib/utils/bindings.ts +++ b/packages/ember-glimmer/lib/utils/bindings.ts @@ -1,14 +1,14 @@ +import { Opaque, Option } from '@glimmer/interfaces'; import { CachedReference, combine, map, - referenceFromParts, Reference, - Tag + referenceFromParts, + Tag, } from '@glimmer/reference'; -import { Opaque, Option } from '@glimmer/interfaces'; import { - Ops + Ops, } from '@glimmer/wire-format'; import { assert } from 'ember-debug'; import { get } from 'ember-metal'; @@ -97,7 +97,7 @@ export const AttributeBinding = { } operations.addDynamicAttribute(element, attribute, reference); - } + }, }; const DISPLAY_NONE = 'display: none;'; @@ -133,7 +133,7 @@ export const IsVisibleBinding = { mapStyleValue(isVisible) { return isVisible === false ? SAFE_DISPLAY_NONE : null; - } + }, }; export const ClassNameBinding = { @@ -157,7 +157,7 @@ export const ClassNameBinding = { operations.addDynamicAttribute(element, 'class', ref); } - } + }, }; class SimpleClassNameBindingReference extends CachedReference> { diff --git a/packages/ember-glimmer/lib/utils/curly-component-state-bucket.ts b/packages/ember-glimmer/lib/utils/curly-component-state-bucket.ts index 3f7b851da2b..e19b4bb1850 100644 --- a/packages/ember-glimmer/lib/utils/curly-component-state-bucket.ts +++ b/packages/ember-glimmer/lib/utils/curly-component-state-bucket.ts @@ -7,7 +7,12 @@ interface Environment { } interface Component { + _debugContainerKey: string; trigger(event: string); + destroy(): void; + setProperties(props: { + [key: string]: any; + }): void; } type Finalizer = () => void; @@ -25,9 +30,9 @@ function NOOP() {} */ export default class ComponentStateBucket { public classRef: Opaque = null; - private argsRevision: Revision; + public argsRevision: Revision; - constructor(private environment: Environment, private component: Component, private args: Tagged, private finalizer: Finalizer) { + constructor(public environment: Environment, public component: Component, public args: Tagged, public finalizer: Finalizer) { this.classRef = null; this.argsRevision = args.tag.value(); } diff --git a/packages/ember-glimmer/lib/utils/iterable.ts b/packages/ember-glimmer/lib/utils/iterable.ts index bed9be71401..ba82dd2274f 100644 --- a/packages/ember-glimmer/lib/utils/iterable.ts +++ b/packages/ember-glimmer/lib/utils/iterable.ts @@ -1,22 +1,22 @@ -import { guidFor } from 'ember-utils'; -import { get, tagForProperty, tagFor, isProxy } from 'ember-metal'; -import { - objectAt, - isEmberArray -} from 'ember-runtime'; -import { - UpdatableReference, - UpdatablePrimitiveReference -} from './references'; -import { isEachIn } from '../helpers/each-in'; import { + combine, CONSTANT_TAG, IterationItem, TagWrapper, UpdatableTag, - combine } from '@glimmer/reference'; import { Opaque } from '@glimmer/util'; +import { get, isProxy, tagFor, tagForProperty } from 'ember-metal'; +import { + isEmberArray, + objectAt, +} from 'ember-runtime'; +import { guidFor } from 'ember-utils'; +import { isEachIn } from '../helpers/each-in'; +import { + UpdatablePrimitiveReference, + UpdatableReference, +} from './references'; const ITERATOR_KEY_GUID = 'be277757-bbbe-4620-9fcb-213ef433cca2'; @@ -82,7 +82,7 @@ function ensureUniqueKey(seen, key) { } class ArrayIterator { - public array: Array; + public array: any[]; public length: number; public keyFor: (value: any, memo: any) => any; public position: number; @@ -135,7 +135,7 @@ class EmberArrayIterator extends ArrayIterator { } class ObjectKeysIterator extends ArrayIterator { - public keys: Array; + public keys: any[]; public length: number; constructor(keys, values, keyFor) { @@ -190,7 +190,7 @@ class EachInIterable { if (iterable !== null && (typeofIterable === 'object' || typeofIterable === 'function')) { let keys = Object.keys(iterable); - let values = keys.map(key => iterable[key]); + let values = keys.map((key) => iterable[key]); return keys.length > 0 ? new ObjectKeysIterator(keys, values, keyFor) : EMPTY_ITERATOR; } else { return EMPTY_ITERATOR; @@ -248,7 +248,7 @@ class ArrayIterable { } else if (isEmberArray(iterable)) { return get(iterable, 'length') > 0 ? new EmberArrayIterator(iterable, keyFor) : EMPTY_ITERATOR; } else if (typeof iterable.forEach === 'function') { - let array: Array = []; + let array: any[] = []; iterable.forEach(function(item) { array.push(item); }); diff --git a/packages/ember-glimmer/lib/utils/process-args.ts b/packages/ember-glimmer/lib/utils/process-args.ts index 3c9cdb8848e..6b9a929f696 100644 --- a/packages/ember-glimmer/lib/utils/process-args.ts +++ b/packages/ember-glimmer/lib/utils/process-args.ts @@ -1,8 +1,8 @@ import { symbol } from 'ember-utils'; -import { ARGS } from '../component'; -import { UPDATE } from './references'; import { MUTABLE_CELL } from 'ember-views'; +import { ARGS } from '../component'; import { ACTION } from '../helpers/action'; +import { UPDATE } from './references'; // ComponentArgs takes EvaluatedNamedArgs and converts them into the // inputs needed by CurlyComponents (attrs and props, with mutable diff --git a/packages/ember-glimmer/lib/utils/references.ts b/packages/ember-glimmer/lib/utils/references.ts index 627a337c779..2dd02ae0a21 100644 --- a/packages/ember-glimmer/lib/utils/references.ts +++ b/packages/ember-glimmer/lib/utils/references.ts @@ -1,39 +1,39 @@ import { - HAS_NATIVE_WEAKMAP, - Opaque, - symbol -} from 'ember-utils'; -import { - get, - set, - tagForProperty, - tagFor, - didRender, - watchKey, - isProxy -} from 'ember-metal'; -import { + combine, CONSTANT_TAG, ConstReference, DirtyableTag, - UpdatableTag, + isConst, TagWrapper, + UpdatableTag, VersionedPathReference, - combine, - isConst } from '@glimmer/reference'; import { ConditionalReference as GlimmerConditionalReference, - PrimitiveReference + PrimitiveReference, } from '@glimmer/runtime'; -import emberToBool from './to-bool'; -import { RECOMPUTE_TAG } from '../helper'; import { DEBUG } from 'ember-env-flags'; import { - EMBER_GLIMMER_DETECT_BACKTRACKING_RERENDER, + didRender, + get, + isProxy, + set, + tagFor, + tagForProperty, + watchKey, +} from 'ember-metal'; +import { + HAS_NATIVE_WEAKMAP, + Opaque, + symbol, +} from 'ember-utils'; +import { EMBER_GLIMMER_ALLOW_BACKTRACKING_RERENDER, - MANDATORY_SETTER + EMBER_GLIMMER_DETECT_BACKTRACKING_RERENDER, + MANDATORY_SETTER, } from 'ember/features'; +import { RECOMPUTE_TAG } from '../helper'; +import emberToBool from './to-bool'; export const UPDATE = symbol('UPDATE'); @@ -50,7 +50,7 @@ if (DEBUG) { if (!Object.isFrozen(obj) && HAS_NATIVE_WEAKMAP) { Object.freeze(obj); } - } + }; } // @abstract @@ -93,9 +93,10 @@ export class CachedReference extends EmberPathReference { } // @implements PathReference -export class RootReference extends ConstReference { +export class RootReference extends ConstReference { public children: any; - constructor(value) { + + constructor(value: T) { super(value); this.children = Object.create(null); } diff --git a/packages/ember-glimmer/lib/utils/string.ts b/packages/ember-glimmer/lib/utils/string.ts index c3a078edbf3..af50fbf9782 100644 --- a/packages/ember-glimmer/lib/utils/string.ts +++ b/packages/ember-glimmer/lib/utils/string.ts @@ -27,8 +27,8 @@ export function getSafeString() { { id: 'ember-htmlbars.ember-handlebars-safestring', until: '3.0.0', - url: 'https://emberjs.com/deprecations/v2.x#toc_use-ember-string-htmlsafe-over-ember-handlebars-safestring' - } + url: 'https://emberjs.com/deprecations/v2.x#toc_use-ember-string-htmlsafe-over-ember-handlebars-safestring', + }, ); return SafeString; @@ -43,7 +43,7 @@ const escape = { "'": ''', // jscs:enable '`': '`', - '=': '=' + '=': '=', }; const possible = /[&<>"'`=]/; diff --git a/packages/ember-glimmer/lib/utils/to-bool.ts b/packages/ember-glimmer/lib/utils/to-bool.ts index ce7bac57728..de09e00524b 100644 --- a/packages/ember-glimmer/lib/utils/to-bool.ts +++ b/packages/ember-glimmer/lib/utils/to-bool.ts @@ -1,5 +1,5 @@ -import { isArray } from 'ember-runtime'; import { get } from 'ember-metal'; +import { isArray } from 'ember-runtime'; export default function toBool(predicate) { if (!predicate) { diff --git a/packages/ember-glimmer/lib/views/outlet.ts b/packages/ember-glimmer/lib/views/outlet.ts index 0cd4ef80dc3..26f080d8a1d 100644 --- a/packages/ember-glimmer/lib/views/outlet.ts +++ b/packages/ember-glimmer/lib/views/outlet.ts @@ -1,31 +1,32 @@ -import { assign } from 'ember-utils'; -import { DirtyableTag } from '@glimmer/reference'; +import { Simple } from '@glimmer/interfaces'; +import { DirtyableTag, VersionedPathReference } from '@glimmer/reference'; import { environment } from 'ember-environment'; -import { OWNER } from 'ember-utils'; import { run } from 'ember-metal'; +import { assign } from 'ember-utils'; +import { OWNER } from 'ember-utils'; +import Environment from '../environment'; +import { Renderer } from '../renderer'; -class OutletStateReference { - public outletView: any; +export class OutletStateReference implements VersionedPathReference { public tag: any; - constructor(outletView) { - this.outletView = outletView; + constructor(public outletView: OutletView) { this.tag = outletView._tag; } - get(key) { + get(key: string): VersionedPathReference { return new ChildOutletStateReference(this, key); } - value() { + value(): OutletState { return this.outletView.outletState; } - getOrphan(name) { + getOrphan(name: string): VersionedPathReference { return new OrphanedOutletStateReference(this, name); } - update(state) { + update(state: OutletState) { this.outletView.setOutletState(state); } } @@ -43,7 +44,7 @@ class OrphanedOutletStateReference extends OutletStateReference { this.name = name; } - value() { + value(): OutletState { let rootState = this.root.value(); let orphans = rootState.outlets.main.outlets.__ember_orphans__; @@ -61,7 +62,7 @@ class OrphanedOutletStateReference extends OutletStateReference { let state = Object.create(null); state[matched.render.outlet] = matched; matched.wasUsed = true; - return { outlets: state }; + return { outlets: state, render: undefined }; } } @@ -85,13 +86,28 @@ class ChildOutletStateReference { } } +export interface OutletState { + outlets: { + [name: string]: OutletState; + }; + render: { + owner: any | undefined, + into: string, + outlet: string, + name: string, + controller: any | undefined, + ViewClass: Function | undefined, + template: any | undefined, + }; +} + export default class OutletView { - private _environment: any; - public renderer: any; + private _environment: Environment; + public renderer: Renderer; public owner: any; public template: any; - public outletState: any; - private _tag: any; + public outletState: OutletState; + public _tag: DirtyableTag; static extend(injections) { return class extends OutletView { @@ -124,7 +140,7 @@ export default class OutletView { this._tag = new DirtyableTag(); } - appendTo(selector) { + appendTo(selector: string | Simple.Element) { let env = this._environment || environment; let target; @@ -139,10 +155,10 @@ export default class OutletView { rerender() { } - setOutletState(state) { + setOutletState(state: OutletState) { this.outletState = { outlets: { - main: state + main: state, }, render: { owner: undefined, @@ -151,8 +167,8 @@ export default class OutletView { name: '-top-level', controller: undefined, ViewClass: undefined, - template: undefined - } + template: undefined, + }, }; this._tag.dirty(); } diff --git a/yarn.lock b/yarn.lock index 7a3b48e852e..4022d73c8a2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -186,6 +186,12 @@ ansi-styles@^2.0.1, ansi-styles@^2.1.0, ansi-styles@^2.2.1: version "2.2.1" resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe" +ansi-styles@^3.1.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.0.tgz#c159b8d5be0f9e5a6f346dab94f16ce022161b88" + dependencies: + color-convert "^1.9.0" + ansicolors@~0.2.1: version "0.2.1" resolved "https://registry.yarnpkg.com/ansicolors/-/ansicolors-0.2.1.tgz#be089599097b74a5c9c4a84a0cdbcdb62bd87aef" @@ -1393,7 +1399,7 @@ buffer@4.9.1: ieee754 "^1.1.4" isarray "^1.0.0" -builtin-modules@^1.0.0: +builtin-modules@^1.0.0, builtin-modules@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-1.1.1.tgz#270f076c5a72c02f5b65a47df94c5fe3a278892f" @@ -1519,6 +1525,14 @@ chalk@^1.0.0, chalk@^1.1.0, chalk@^1.1.1, chalk@^1.1.3: strip-ansi "^3.0.0" supports-color "^2.0.0" +chalk@^2.1.0: + version "2.3.0" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.3.0.tgz#b5ea48efc9c1793dccc9b4767c93914d3f2d52ba" + dependencies: + ansi-styles "^3.1.0" + escape-string-regexp "^1.0.5" + supports-color "^4.0.0" + charm@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/charm/-/charm-1.0.2.tgz#8add367153a6d9a581331052c4090991da995e35" @@ -1626,6 +1640,16 @@ code-point-at@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77" +color-convert@^1.9.0: + version "1.9.0" + resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.0.tgz#1accf97dd739b983bf994d56fec8f95853641b7a" + dependencies: + color-name "^1.1.1" + +color-name@^1.1.1: + version "1.1.3" + resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25" + colors@1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/colors/-/colors-1.0.3.tgz#0433f44d809680fdeb60ed260f1b0c262e82a40b" @@ -2031,6 +2055,10 @@ diff@1.4.0, diff@^1.3.1: version "1.4.0" resolved "https://registry.yarnpkg.com/diff/-/diff-1.4.0.tgz#7f28d2eb9ee7b15a97efd89ce63dcfdaa3ccbabf" +diff@^3.2.0: + version "3.4.0" + resolved "https://registry.yarnpkg.com/diff/-/diff-3.4.0.tgz#b1d85507daf3964828de54b37d0d73ba67dda56c" + doctrine@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-2.0.0.tgz#c73d8d2909d22291e1a007a395804da8b665fe63" @@ -3267,6 +3295,10 @@ has-cors@1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/has-cors/-/has-cors-1.1.0.tgz#5e474793f7ea9843d1bb99c23eef49ff126fff39" +has-flag@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-2.0.0.tgz#e8207af1cc7b30d446cc70b734b5e8be18f88d51" + has-unicode@^2.0.0, has-unicode@~2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/has-unicode/-/has-unicode-2.0.1.tgz#e0e6fe6a28cf51138855e086d1691e771de2a8b9" @@ -4294,7 +4326,7 @@ minimatch@0.3: lru-cache "2" sigmund "~1.0.0" -"minimatch@2 || 3", minimatch@^3.0.0, minimatch@^3.0.2, minimatch@^3.0.3: +"minimatch@2 || 3", minimatch@^3.0.0, minimatch@^3.0.2, minimatch@^3.0.3, minimatch@^3.0.4: version "3.0.4" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" dependencies: @@ -5329,6 +5361,12 @@ resolve@^1.1.2, resolve@^1.1.6, resolve@^1.3.3: dependencies: path-parse "^1.0.5" +resolve@^1.3.2: + version "1.5.0" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.5.0.tgz#1f09acce796c9a762579f31b2c1cc4c3cddf9f36" + dependencies: + path-parse "^1.0.5" + restore-cursor@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-1.0.1.tgz#34661f46886327fed2991479152252df92daa541" @@ -5834,6 +5872,12 @@ supports-color@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7" +supports-color@^4.0.0: + version "4.5.0" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-4.5.0.tgz#be7a0de484dec5c5cddf8b3d59125044912f635b" + dependencies: + has-flag "^2.0.0" + symlink-or-copy@^1.0.0, symlink-or-copy@^1.0.1, symlink-or-copy@^1.1.8: version "1.1.8" resolved "https://registry.yarnpkg.com/symlink-or-copy/-/symlink-or-copy-1.1.8.tgz#cabe61e0010c1c023c173b25ee5108b37f4b4aa3" @@ -6002,6 +6046,32 @@ tryor@~0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/tryor/-/tryor-0.1.2.tgz#8145e4ca7caff40acde3ccf946e8b8bb75b4172b" +tslib@^1.7.1: + version "1.8.0" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.8.0.tgz#dc604ebad64bcbf696d613da6c954aa0e7ea1eb6" + +tslint@^5.8.0: + version "5.8.0" + resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.8.0.tgz#1f49ad5b2e77c76c3af4ddcae552ae4e3612eb13" + dependencies: + babel-code-frame "^6.22.0" + builtin-modules "^1.1.1" + chalk "^2.1.0" + commander "^2.9.0" + diff "^3.2.0" + glob "^7.1.1" + minimatch "^3.0.4" + resolve "^1.3.2" + semver "^5.3.0" + tslib "^1.7.1" + tsutils "^2.12.1" + +tsutils@^2.12.1: + version "2.12.1" + resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-2.12.1.tgz#f4d95ce3391c8971e46e54c4cf0edb0a21dd5b24" + dependencies: + tslib "^1.7.1" + tunnel-agent@^0.6.0: version "0.6.0" resolved "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.6.0.tgz#27a5dea06b36b04a0a9966774b290868f0fc40fd" From 3c74b385a7d0e2b1ee7ec75b52723e87173fb82a Mon Sep 17 00:00:00 2001 From: Kris Selden Date: Wed, 25 Oct 2017 18:27:56 -0700 Subject: [PATCH 17/24] add more strictness and few more types. --- .../lib/component-managers/abstract.ts | 26 ++++++++++--------- .../lib/component-managers/mount.ts | 4 +-- .../lib/component-managers/outlet.ts | 12 ++++----- .../lib/component-managers/render.ts | 13 +++++----- .../lib/component-managers/root.ts | 5 +--- .../ember-glimmer/lib/components/link-to.ts | 4 +-- .../lib/components/text_field.ts | 2 +- packages/ember-glimmer/lib/environment.ts | 13 ++++------ packages/ember-glimmer/lib/helpers/-class.ts | 2 +- .../ember-glimmer/lib/helpers/-html-safe.ts | 2 +- .../ember-glimmer/lib/helpers/-input-type.ts | 4 +-- .../lib/helpers/-normalize-class.ts | 4 +-- packages/ember-glimmer/lib/helpers/action.ts | 16 +++++++----- .../ember-glimmer/lib/helpers/component.ts | 13 +++++++--- packages/ember-glimmer/lib/helpers/concat.ts | 2 +- packages/ember-glimmer/lib/helpers/each-in.ts | 2 +- packages/ember-glimmer/lib/helpers/get.ts | 2 +- packages/ember-glimmer/lib/helpers/hash.ts | 2 +- .../ember-glimmer/lib/helpers/if-unless.ts | 4 +-- packages/ember-glimmer/lib/helpers/loc.ts | 2 +- packages/ember-glimmer/lib/helpers/log.ts | 2 +- packages/ember-glimmer/lib/helpers/mut.ts | 2 +- .../ember-glimmer/lib/helpers/query-param.ts | 3 ++- .../ember-glimmer/lib/helpers/readonly.ts | 2 +- packages/ember-glimmer/lib/helpers/unbound.ts | 2 +- .../ember-glimmer/lib/modifiers/action.ts | 2 +- packages/ember-glimmer/lib/renderer.ts | 25 +++++++----------- .../ember-glimmer/lib/syntax/-text-area.ts | 2 +- .../lib/syntax/dynamic-component.ts | 8 +++--- packages/ember-glimmer/lib/syntax/input.ts | 2 +- packages/ember-glimmer/lib/syntax/mount.ts | 3 +-- packages/ember-glimmer/lib/syntax/outlet.ts | 2 +- packages/ember-glimmer/lib/syntax/render.ts | 6 ++++- packages/ember-glimmer/lib/utils/iterable.ts | 6 ++--- .../ember-glimmer/lib/utils/references.ts | 4 +-- tsconfig.json | 6 ++--- 36 files changed, 104 insertions(+), 107 deletions(-) diff --git a/packages/ember-glimmer/lib/component-managers/abstract.ts b/packages/ember-glimmer/lib/component-managers/abstract.ts index 52578116d1f..024ed4d28d6 100644 --- a/packages/ember-glimmer/lib/component-managers/abstract.ts +++ b/packages/ember-glimmer/lib/component-managers/abstract.ts @@ -2,7 +2,6 @@ import { ProgramSymbolTable } from '@glimmer/interfaces'; import { Tag, VersionedPathReference } from '@glimmer/reference'; import { Bounds, - CompiledDynamicProgram, CompiledDynamicTemplate, ComponentDefinition, ComponentManager, @@ -12,15 +11,16 @@ import { PreparedArguments, } from '@glimmer/runtime'; import { IArguments } from '@glimmer/runtime/dist/types/lib/vm/arguments'; -import { Destroyable, Opaque, Option } from '@glimmer/util'; +import { Destroyable, Option } from '@glimmer/util'; import { DEBUG } from 'ember-env-flags'; +import DebugStack from '../utils/debug-stack'; // implements the ComponentManager interface as defined in glimmer: // tslint:disable-next-line:max-line-length // https://github.com/glimmerjs/glimmer-vm/blob/v0.24.0-beta.4/packages/%40glimmer/runtime/lib/component/interfaces.ts#L21 export default abstract class AbstractManager implements ComponentManager { - public debugStack: any; + public debugStack: typeof DebugStack; public _pushToDebugStack: (name: string, environment: any) => void; public _pushEngineToDebugStack: (name: string, environment: any) => void; @@ -28,7 +28,7 @@ export default abstract class AbstractManager implements ComponentManager this.debugStack = undefined; } - prepareArgs(definition: ComponentDefinition, args: IArguments): Option { + prepareArgs(_definition: ComponentDefinition, _args: IArguments): Option { return null; } @@ -44,41 +44,43 @@ export default abstract class AbstractManager implements ComponentManager caller: VersionedPathReference, hasDefaultBlock: boolean): T; abstract layoutFor( - definition: ComponentDefinition, component: T, env: Environment): CompiledDynamicTemplate; + definition: ComponentDefinition, + component: T, + env: Environment): CompiledDynamicTemplate; abstract getSelf(component: T): VersionedPathReference; - didCreateElement(component: T, element: Element, operations: ElementOperations): void { + didCreateElement(_component: T, _element: Element, _operations: ElementOperations): void { // noop } // inheritors should also call `this.debugStack.pop()` to // ensure the rerendering assertion messages are properly // maintained - didRenderLayout(component: T, bounds: Bounds): void { + didRenderLayout(_component: T, _bounds: Bounds): void { // noop } - didCreate(bucket: T): void { + didCreate(_bucket: T): void { // noop } - getTag(bucket: T): Option { return null; } + getTag(_bucket: T): Option { return null; } // inheritors should also call `this._pushToDebugStack` // to ensure the rerendering assertion messages are // properly maintained - update(bucket: T, dynamicScope: DynamicScope): void { + update(_bucket: T, _dynamicScope: DynamicScope): void { // noop } // inheritors should also call `this.debugStack.pop()` to // ensure the rerendering assertion messages are properly // maintained - didUpdateLayout(bucket: T, bounds: Bounds): void { + didUpdateLayout(_bucket: T, _bounds: Bounds): void { // noop } - didUpdate(bucket: T): void { + didUpdate(_bucket: T): void { // noop } diff --git a/packages/ember-glimmer/lib/component-managers/mount.ts b/packages/ember-glimmer/lib/component-managers/mount.ts index 6b6f52c35a6..461d558b582 100644 --- a/packages/ember-glimmer/lib/component-managers/mount.ts +++ b/packages/ember-glimmer/lib/component-managers/mount.ts @@ -23,7 +23,7 @@ interface EngineBucket { } class MountManager extends AbstractManager { - create(environment, { name }, args, dynamicScope) { + create(environment, { name }, args) { if (DEBUG) { this._pushEngineToDebugStack(`engine:${name}`, environment); } @@ -41,7 +41,7 @@ class MountManager extends AbstractManager { return bucket; } - layoutFor(definition, { engine }, env) { + layoutFor(_definition, { engine }, env) { let template = engine.lookup(`template:application`); return env.getCompiledBlock(OutletLayoutCompiler, template); } diff --git a/packages/ember-glimmer/lib/component-managers/outlet.ts b/packages/ember-glimmer/lib/component-managers/outlet.ts index 688b6be51b2..cb46f4a7a9e 100644 --- a/packages/ember-glimmer/lib/component-managers/outlet.ts +++ b/packages/ember-glimmer/lib/component-managers/outlet.ts @@ -42,7 +42,7 @@ class StateBucket { } class OutletComponentManager extends AbstractManager { - create(environment: Environment, definition: OutletComponentDefinition, args, dynamicScope: OutletDynamicScope) { + create(environment: Environment, definition: OutletComponentDefinition, _args, dynamicScope: OutletDynamicScope) { if (DEBUG) { this._pushToDebugStack(`template:${definition.template.meta.moduleName}`, environment); } @@ -53,7 +53,7 @@ class OutletComponentManager extends AbstractManager { return new StateBucket(outletState); } - layoutFor(definition, bucket, env) { + layoutFor(definition, _bucket, env: Environment) { return env.getCompiledBlock(OutletLayoutCompiler, definition.template); } @@ -61,7 +61,7 @@ class OutletComponentManager extends AbstractManager { return new RootReference(outletState.render.controller); } - didRenderLayout(bucket) { + didRenderLayout(bucket: StateBucket) { bucket.finalize(); if (DEBUG) { @@ -69,7 +69,7 @@ class OutletComponentManager extends AbstractManager { } } - getDestructor(bucket: StateBucket): Option { + getDestructor(): Option { return null; } } @@ -77,14 +77,14 @@ class OutletComponentManager extends AbstractManager { const MANAGER = new OutletComponentManager(); class TopLevelOutletComponentManager extends OutletComponentManager { - create(environment, definition, args, dynamicScope) { + create(environment, definition, _args, dynamicScope) { if (DEBUG) { this._pushToDebugStack(`template:${definition.template.meta.moduleName}`, environment); } return new StateBucket(dynamicScope.outletState.value()); } - layoutFor(definition, bucket, env) { + layoutFor(definition, _bucket, env) { return env.getCompiledBlock(TopLevelOutletLayoutCompiler, definition.template); } } diff --git a/packages/ember-glimmer/lib/component-managers/render.ts b/packages/ember-glimmer/lib/component-managers/render.ts index 7d18834b193..b6b929ac06a 100644 --- a/packages/ember-glimmer/lib/component-managers/render.ts +++ b/packages/ember-glimmer/lib/component-managers/render.ts @@ -1,13 +1,9 @@ -import { - VersionedPathReference, -} from '@glimmer/reference'; import { ComponentDefinition, } from '@glimmer/runtime'; import { IArguments } from '@glimmer/runtime/dist/types/lib/vm/arguments'; import { Destroyable } from '@glimmer/util'; -import { assert } from 'ember-debug'; import { DEBUG } from 'ember-env-flags'; import { generateController, generateControllerFactory } from 'ember-routing'; import Environment from '../environment'; @@ -17,7 +13,7 @@ import AbstractManager from './abstract'; import { OutletLayoutCompiler } from './outlet'; export abstract class AbstractRenderManager extends AbstractManager { - layoutFor(definition, bucket, env) { + layoutFor(definition: RenderDefinition, _bucket, env) { return env.getCompiledBlock(OutletLayoutCompiler, definition.template); } @@ -37,7 +33,10 @@ export interface RenderState { } class SingletonRenderManager extends AbstractRenderManager { - create(env: Environment, definition: ComponentDefinition, args: IArguments, dynamicScope: DynamicScope) { + create(env: Environment, + definition: ComponentDefinition, + _args: IArguments, + dynamicScope: DynamicScope) { let { name } = definition; let controller = env.owner.lookup(`controller:${name}`) || generateController(env.owner, name); @@ -79,7 +78,7 @@ class NonSingletonRenderManager extends AbstractRenderManager { return { controller, model: modelRef }; } - update({ controller, model }, dynamicScope) { + update({ controller, model }) { controller.set('model', model.value()); } diff --git a/packages/ember-glimmer/lib/component-managers/root.ts b/packages/ember-glimmer/lib/component-managers/root.ts index 24d6f484c0b..a8388037002 100644 --- a/packages/ember-glimmer/lib/component-managers/root.ts +++ b/packages/ember-glimmer/lib/component-managers/root.ts @@ -1,9 +1,6 @@ import { ComponentDefinition, } from '@glimmer/runtime'; -import { - assert, -} from 'ember-debug'; import { DEBUG } from 'ember-env-flags'; import { _instrumentStart, @@ -15,7 +12,7 @@ import CurlyComponentManager, { } from './curly'; class RootComponentManager extends CurlyComponentManager { - create(environment, definition, args, dynamicScope, currentScope, hasBlock) { + create(environment, definition, args, dynamicScope) { let component = definition.ComponentClass.create(); if (DEBUG) { diff --git a/packages/ember-glimmer/lib/components/link-to.ts b/packages/ember-glimmer/lib/components/link-to.ts index f2c5254ae8a..584ce23c057 100644 --- a/packages/ember-glimmer/lib/components/link-to.ts +++ b/packages/ember-glimmer/lib/components/link-to.ts @@ -543,10 +543,10 @@ const LinkComponent = EmberComponent.extend({ @private */ disabled: computed({ - get(key, value) { + get(_key) { return false; }, - set(key, value) { + set(_key, value) { if (value !== undefined) { this.set('_isDisabled', value); } return value ? get(this, 'disabledClass') : false; diff --git a/packages/ember-glimmer/lib/components/text_field.ts b/packages/ember-glimmer/lib/components/text_field.ts index ef4fa752d4b..f6a78ceeb3a 100644 --- a/packages/ember-glimmer/lib/components/text_field.ts +++ b/packages/ember-glimmer/lib/components/text_field.ts @@ -103,7 +103,7 @@ export default Component.extend(TextSupport, { return 'text'; }, - set(key, value) { + set(_key, value) { let type = 'text'; if (canSetTypeOfInput(value)) { diff --git a/packages/ember-glimmer/lib/environment.ts b/packages/ember-glimmer/lib/environment.ts index cfebd674cbd..4de2f712939 100644 --- a/packages/ember-glimmer/lib/environment.ts +++ b/packages/ember-glimmer/lib/environment.ts @@ -1,11 +1,9 @@ -/// import { Reference, } from '@glimmer/reference'; import { AttributeManager, compileLayout, - DOMTreeConstruction, Environment as GlimmerEnvironment, getDynamicVar, isSafeString, @@ -14,7 +12,7 @@ import { import { Destroyable, Opaque, } from '@glimmer/util'; -import { assert, warn } from 'ember-debug'; +import { warn } from 'ember-debug'; import { DEBUG } from 'ember-env-flags'; import { _instrumentStart, Cache } from 'ember-metal'; import { guidFor, OWNER } from 'ember-utils'; @@ -62,7 +60,6 @@ import { default as unbound } from './helpers/unbound'; import { default as ActionModifierManager } from './modifiers/action'; import installPlatformSpecificProtocolForURL from './protocol-for-url'; -import { DOMChanges } from '@glimmer/runtime/dist/types/lib/dom/helper'; import { EMBER_MODULE_UNIFICATION, GLIMMER_CUSTOM_COMPONENT_MANAGER, @@ -95,8 +92,8 @@ export default class Environment extends GlimmerEnvironment { constructor(injections: any) { super(injections); - let owner = this.owner = injections[OWNER]; - this.isInteractive = owner.lookup('-environment:main').isInteractive; + this.owner = injections[OWNER]; + this.isInteractive = this.owner.lookup('-environment:main').isInteractive; // can be removed once https://github.com/tildeio/glimmer/pull/305 lands this.destroyedComponents = []; @@ -262,7 +259,7 @@ export default class Environment extends GlimmerEnvironment { // TODO: try to unify this into a consistent protocol to avoid wasteful closure allocations if (helperFactory.class.isHelperInstance) { - return (vm, args) => SimpleHelperReference.create(helperFactory.class.compute, args.capture()); + return (_vm, args) => SimpleHelperReference.create(helperFactory.class.compute, args.capture()); } else if (helperFactory.class.isHelperFactory) { return (vm, args) => ClassBasedHelperReference.create(helperFactory, vm, args.capture()); } else { @@ -355,7 +352,7 @@ if (DEBUG) { let STYLE_ATTRIBUTE_MANANGER = new StyleAttributeManager('style'); - Environment.prototype.attributeFor = function(element, attribute, isTrusting, namespace) { + Environment.prototype.attributeFor = function(element, attribute, isTrusting) { if (attribute === 'style' && !isTrusting) { return STYLE_ATTRIBUTE_MANANGER; } diff --git a/packages/ember-glimmer/lib/helpers/-class.ts b/packages/ember-glimmer/lib/helpers/-class.ts index 6dc8f5d3705..13dd3b18c65 100644 --- a/packages/ember-glimmer/lib/helpers/-class.ts +++ b/packages/ember-glimmer/lib/helpers/-class.ts @@ -23,6 +23,6 @@ function classHelper({ positional }) { return value; } -export default function(vm, args) { +export default function(_vm, args) { return new InternalHelperReference(classHelper, args.capture()); } diff --git a/packages/ember-glimmer/lib/helpers/-html-safe.ts b/packages/ember-glimmer/lib/helpers/-html-safe.ts index 96c67162158..df6a2fd28e5 100644 --- a/packages/ember-glimmer/lib/helpers/-html-safe.ts +++ b/packages/ember-glimmer/lib/helpers/-html-safe.ts @@ -6,6 +6,6 @@ function htmlSafe({ positional }) { return new SafeString(path.value()); } -export default function(vm, args) { +export default function(_vm, args) { return new InternalHelperReference(htmlSafe, args.capture()); } diff --git a/packages/ember-glimmer/lib/helpers/-input-type.ts b/packages/ember-glimmer/lib/helpers/-input-type.ts index eacf20d1e3b..2196d3fe6ec 100644 --- a/packages/ember-glimmer/lib/helpers/-input-type.ts +++ b/packages/ember-glimmer/lib/helpers/-input-type.ts @@ -1,6 +1,6 @@ import { InternalHelperReference } from '../utils/references'; -function inputTypeHelper({ positional, named }) { +function inputTypeHelper({ positional }) { let type = positional.at(0).value(); if (type === 'checkbox') { return '-checkbox'; @@ -8,6 +8,6 @@ function inputTypeHelper({ positional, named }) { return '-text-field'; } -export default function(vm, args) { +export default function(_vm, args) { return new InternalHelperReference(inputTypeHelper, args.capture()); } diff --git a/packages/ember-glimmer/lib/helpers/-normalize-class.ts b/packages/ember-glimmer/lib/helpers/-normalize-class.ts index beaef34c08a..271b3db18b4 100644 --- a/packages/ember-glimmer/lib/helpers/-normalize-class.ts +++ b/packages/ember-glimmer/lib/helpers/-normalize-class.ts @@ -1,7 +1,7 @@ import { String as StringUtils } from 'ember-runtime'; import { InternalHelperReference } from '../utils/references'; -function normalizeClass({ positional, named }) { +function normalizeClass({ positional }) { let classNameParts = positional.at(0).value().split('.'); let className = classNameParts[classNameParts.length - 1]; let value = positional.at(1).value(); @@ -15,6 +15,6 @@ function normalizeClass({ positional, named }) { } } -export default function(vm, args) { +export default function(_vm, args) { return new InternalHelperReference(normalizeClass, args.capture()); } diff --git a/packages/ember-glimmer/lib/helpers/action.ts b/packages/ember-glimmer/lib/helpers/action.ts index d9d54ee3e7e..9de1bf243ba 100644 --- a/packages/ember-glimmer/lib/helpers/action.ts +++ b/packages/ember-glimmer/lib/helpers/action.ts @@ -270,7 +270,7 @@ export const ACTION = symbol('ACTION'); @for Ember.Templates.helpers @public */ -export default function(vm, args): UnboundReference { +export default function(_vm, args): UnboundReference { let { named, positional } = args; let capturedArgs = positional.capture(); @@ -308,7 +308,7 @@ function makeArgsProcessor(valuePathRef, actionArgsRef) { let mergeArgs = null; if (actionArgsRef.length > 0) { - mergeArgs = function(args) { + mergeArgs = (args) => { return actionArgsRef.map((ref) => ref.value()).concat(args); }; } @@ -316,7 +316,7 @@ function makeArgsProcessor(valuePathRef, actionArgsRef) { let readValue = null; if (valuePathRef) { - readValue = function(args) { + readValue = (args) => { let valuePath = valuePathRef.value(); if (valuePath && args.length > 0) { @@ -328,7 +328,7 @@ function makeArgsProcessor(valuePathRef, actionArgsRef) { } if (mergeArgs && readValue) { - return function(args) { + return (args) => { return readValue(mergeArgs(args)); }; } else { @@ -342,13 +342,14 @@ function makeDynamicClosureAction(context, targetRef, actionRef, processArgs, de makeClosureAction(context, targetRef.value(), actionRef.value(), processArgs, debugKey); } - return function(...args) { + return (...args) => { return makeClosureAction(context, targetRef.value(), actionRef.value(), processArgs, debugKey)(...args); }; } function makeClosureAction(context, target, action, processArgs, debugKey) { - let self, fn; + let self; + let fn; assert(`Action passed is null or undefined in (action) from ${target}.`, !isNone(action)); @@ -367,11 +368,12 @@ function makeClosureAction(context, target, action, processArgs, debugKey) { self = context; fn = action; } else { + // tslint:disable-next-line:max-line-length assert(`An action could not be made for \`${debugKey || action}\` in ${target}. Please confirm that you are using either a quoted action name (i.e. \`(action '${debugKey || 'myAction'}')\`) or a function available in ${target}.`, false); } } - return function(...args) { + return (...args) => { let payload = { target: self, args, label: '@glimmer/closure-action' }; return flaggedInstrument('interaction.ember-action', payload, () => { return run.join(self, fn, ...processArgs(args)); diff --git a/packages/ember-glimmer/lib/helpers/component.ts b/packages/ember-glimmer/lib/helpers/component.ts index 40b2f18ea62..ebf5667fd4f 100644 --- a/packages/ember-glimmer/lib/helpers/component.ts +++ b/packages/ember-glimmer/lib/helpers/component.ts @@ -144,6 +144,10 @@ import { CachedReference } from '../utils/references'; @public */ export class ClosureComponentReference extends CachedReference { + static create(args, meta, env) { + return new ClosureComponentReference(args, meta, env); + } + public defRef: any; public tag: any; public args: any; @@ -152,10 +156,6 @@ export class ClosureComponentReference extends CachedReference { public lastDefinition: any; public lastName: string; - static create(args, meta, env) { - return new ClosureComponentReference(args, meta, env); - } - constructor(args, meta, env) { super(); @@ -184,9 +184,14 @@ export class ClosureComponentReference extends CachedReference { this.lastName = nameOrDef; if (typeof nameOrDef === 'string') { + // tslint:disable-next-line:max-line-length assert('You cannot use the input helper as a contextual helper. Please extend TextField or Checkbox to use it as a contextual component.', nameOrDef !== 'input'); + // tslint:disable-next-line:max-line-length assert('You cannot use the textarea helper as a contextual helper. Please extend TextArea to use it as a contextual component.', nameOrDef !== 'textarea'); + definition = env.getComponentDefinition(nameOrDef, meta); + + // tslint:disable-next-line:max-line-length assert(`The component helper cannot be used without a valid component name. You used "${nameOrDef}" via (component "${nameOrDef}")`, definition); } else if (isComponentDefinition(nameOrDef)) { definition = nameOrDef; diff --git a/packages/ember-glimmer/lib/helpers/concat.ts b/packages/ember-glimmer/lib/helpers/concat.ts index d9a289ef8cf..e3cd970ad90 100644 --- a/packages/ember-glimmer/lib/helpers/concat.ts +++ b/packages/ember-glimmer/lib/helpers/concat.ts @@ -25,6 +25,6 @@ function concat({ positional }) { return positional.value().map(normalizeTextValue).join(''); } -export default function(vm, args) { +export default function(_vm, args) { return new InternalHelperReference(concat, args.capture()); } diff --git a/packages/ember-glimmer/lib/helpers/each-in.ts b/packages/ember-glimmer/lib/helpers/each-in.ts index 2c3c548c29a..e00cf342565 100644 --- a/packages/ember-glimmer/lib/helpers/each-in.ts +++ b/packages/ember-glimmer/lib/helpers/each-in.ts @@ -115,7 +115,7 @@ export function isEachIn(ref): boolean { return ref && ref[EACH_IN_REFERENCE]; } -export default function(vm, args) { +export default function(_vm, args) { let ref = Object.create(args.positional.at(0)); ref[EACH_IN_REFERENCE] = true; return ref; diff --git a/packages/ember-glimmer/lib/helpers/get.ts b/packages/ember-glimmer/lib/helpers/get.ts index e897e9998cb..c0c2797a7aa 100644 --- a/packages/ember-glimmer/lib/helpers/get.ts +++ b/packages/ember-glimmer/lib/helpers/get.ts @@ -60,7 +60,7 @@ import { CachedReference, UPDATE } from '../utils/references'; @since 2.1.0 */ -export default function(vm, args) { +export default function(_vm, args) { return GetHelperReference.create(args.positional.at(0), args.positional.at(1)); } diff --git a/packages/ember-glimmer/lib/helpers/hash.ts b/packages/ember-glimmer/lib/helpers/hash.ts index ed8e102b89f..aac38f78b4b 100644 --- a/packages/ember-glimmer/lib/helpers/hash.ts +++ b/packages/ember-glimmer/lib/helpers/hash.ts @@ -41,6 +41,6 @@ @public */ -export default function(vm, args) { +export default function(_vm, args) { return args.named.capture(); } diff --git a/packages/ember-glimmer/lib/helpers/if-unless.ts b/packages/ember-glimmer/lib/helpers/if-unless.ts index 668d7db0c66..46efcf188cf 100644 --- a/packages/ember-glimmer/lib/helpers/if-unless.ts +++ b/packages/ember-glimmer/lib/helpers/if-unless.ts @@ -133,7 +133,7 @@ class ConditionalHelperReference extends CachedReference { @for Ember.Templates.helpers @public */ -export function inlineIf(vm, { positional }) { +export function inlineIf(_vm, { positional }) { assert( 'The inline form of the `if` helper expects two or three arguments, e.g. ' + '`{{if trialExpired "Expired" expiryDate}}`.', @@ -162,7 +162,7 @@ export function inlineIf(vm, { positional }) { @for Ember.Templates.helpers @public */ -export function inlineUnless(vm, { positional }) { +export function inlineUnless(_vm, { positional }) { assert( 'The inline form of the `unless` helper expects two or three arguments, e.g. ' + '`{{unless isFirstLogin "Welcome back!"}}`.', diff --git a/packages/ember-glimmer/lib/helpers/loc.ts b/packages/ember-glimmer/lib/helpers/loc.ts index b6d9d9ac66a..71fedceaead 100644 --- a/packages/ember-glimmer/lib/helpers/loc.ts +++ b/packages/ember-glimmer/lib/helpers/loc.ts @@ -41,6 +41,6 @@ function locHelper({ positional }) { return StringUtils.loc.apply(null, positional.value()); } -export default function(vm, args) { +export default function(_vm, args) { return new InternalHelperReference(locHelper, args.capture()); } diff --git a/packages/ember-glimmer/lib/helpers/log.ts b/packages/ember-glimmer/lib/helpers/log.ts index 43ec0309524..338de39e091 100644 --- a/packages/ember-glimmer/lib/helpers/log.ts +++ b/packages/ember-glimmer/lib/helpers/log.ts @@ -22,6 +22,6 @@ function log({ positional }) { Logger.log.apply(null, positional.value()); } -export default function(vm, args) { +export default function(_vm, args) { return new InternalHelperReference(log, args.capture()); } diff --git a/packages/ember-glimmer/lib/helpers/mut.ts b/packages/ember-glimmer/lib/helpers/mut.ts index d490a779cc3..59864511414 100644 --- a/packages/ember-glimmer/lib/helpers/mut.ts +++ b/packages/ember-glimmer/lib/helpers/mut.ts @@ -86,7 +86,7 @@ export function unMut(ref) { return ref[SOURCE] || ref; } -export default function(vm, args) { +export default function(_vm, args) { let rawRef = args.positional.at(0); if (isMut(rawRef)) { diff --git a/packages/ember-glimmer/lib/helpers/query-param.ts b/packages/ember-glimmer/lib/helpers/query-param.ts index 9c8af51f491..027edf87fc3 100644 --- a/packages/ember-glimmer/lib/helpers/query-param.ts +++ b/packages/ember-glimmer/lib/helpers/query-param.ts @@ -23,6 +23,7 @@ import { InternalHelperReference } from '../utils/references'; @public */ function queryParams({ positional, named }) { + // tslint:disable-next-line:max-line-length assert('The `query-params` helper only accepts hash parameters, e.g. (query-params queryParamPropertyName=\'foo\') as opposed to just (query-params \'foo\')', positional.value().length === 0); return QueryParams.create({ @@ -30,6 +31,6 @@ function queryParams({ positional, named }) { }); } -export default function(vm, args) { +export default function(_vm, args) { return new InternalHelperReference(queryParams, args.capture()); } diff --git a/packages/ember-glimmer/lib/helpers/readonly.ts b/packages/ember-glimmer/lib/helpers/readonly.ts index 031ecf194ea..0598bbba903 100644 --- a/packages/ember-glimmer/lib/helpers/readonly.ts +++ b/packages/ember-glimmer/lib/helpers/readonly.ts @@ -102,7 +102,7 @@ import { unMut } from './mut'; @for Ember.Templates.helpers @private */ -export default function(vm, args) { +export default function(_vm, args) { let ref = unMut(args.positional.at(0)); let wrapped = Object.create(ref); diff --git a/packages/ember-glimmer/lib/helpers/unbound.ts b/packages/ember-glimmer/lib/helpers/unbound.ts index 30cb8f8fe06..95ee8ff87df 100644 --- a/packages/ember-glimmer/lib/helpers/unbound.ts +++ b/packages/ember-glimmer/lib/helpers/unbound.ts @@ -33,7 +33,7 @@ import { UnboundReference } from '../utils/references'; @public */ -export default function(vm, args) { +export default function(_vm, args) { assert( 'unbound helper cannot be called with multiple params or hash params', args.positional.length === 1 && args.named.length === 0, diff --git a/packages/ember-glimmer/lib/modifiers/action.ts b/packages/ember-glimmer/lib/modifiers/action.ts index c276607dfac..b2bf5fd2965 100644 --- a/packages/ember-glimmer/lib/modifiers/action.ts +++ b/packages/ember-glimmer/lib/modifiers/action.ts @@ -164,7 +164,7 @@ export class ActionState { // implements ModifierManager export default class ActionModifierManager { - create(element, args, dynamicScope, dom) { + create(element, args, _dynamicScope, dom) { let { named, positional } = args.capture(); let implicitTarget; let actionName; diff --git a/packages/ember-glimmer/lib/renderer.ts b/packages/ember-glimmer/lib/renderer.ts index 30b33ba1428..f3fada0f3d7 100644 --- a/packages/ember-glimmer/lib/renderer.ts +++ b/packages/ember-glimmer/lib/renderer.ts @@ -1,7 +1,3 @@ -interface FreeformObject { - [key: string]: any; -} - import { Simple } from '@glimmer/interfaces'; import { CURRENT_TAG, VersionedPathReference } from '@glimmer/reference'; import { IteratorResult } from '@glimmer/runtime'; @@ -174,7 +170,7 @@ function loopBegin() { function K() { /* noop */ } let loops = 0; -function loopEnd(current, next) { +function loopEnd() { for (let i = 0; i < renderers.length; i++) { if (!renderers[i]._isValid()) { if (loops > 10) { @@ -193,7 +189,7 @@ function loopEnd(current, next) { backburner.on('begin', loopBegin); backburner.on('end', loopEnd); -export class Renderer { +export abstract class Renderer { private _env: Environment; private _rootTemplate: any; private _viewRegistry: { @@ -223,9 +219,8 @@ export class Renderer { appendOutletView(view: OutletView, target: Simple.Element) { let definition = new TopLevelOutletComponentDefinition(view); let outletStateReference = view.toReference(); - let targetObject = view.outletState.render.controller; - this._appendDefinition(view, definition, target, outletStateReference, targetObject); + this._appendDefinition(view, definition, target, outletStateReference); } appendTo(view: Opaque, target: Simple.Element) { @@ -238,8 +233,7 @@ export class Renderer { root: Opaque, definition: ComponentDefinition, target: Simple.Element, - outletStateReference?: OutletStateReference, - targetObject: Opaque = null) { + outletStateReference?: OutletStateReference) { let self = new RootReference(definition); let dynamicScope = new DynamicScope(null, outletStateReference, outletStateReference); let rootState = new RootState(root, this._env, this._rootTemplate, self, target, dynamicScope); @@ -303,9 +297,7 @@ export class Renderer { this._clearAllRoots(); } - getElement(view) { - // overridden in the subclasses - } + abstract getElement(view: Opaque): Simple.Element | undefined; getBounds(view) { let bounds = view[BOUNDS]; @@ -335,7 +327,8 @@ export class Renderer { _renderRoots() { let { _roots: roots, _env: env, _removedRoots: removedRoots } = this; - let globalShouldReflush, initialRootsLength; + let globalShouldReflush: boolean; + let initialRootsLength: number; do { env.begin(); @@ -453,7 +446,7 @@ export class InertRenderer extends Renderer { return new this(env, rootTemplate, _viewRegistry, false); } - getElement(view) { + getElement(_view: Opaque): Simple.Element | undefined { throw new Error('Accessing `this.element` is not allowed in non-interactive environments (such as FastBoot).'); } } @@ -463,7 +456,7 @@ export class InteractiveRenderer extends Renderer { return new this(env, rootTemplate, _viewRegistry, true); } - getElement(view) { + getElement(view: Opaque): Simple.Element | undefined { return getViewElement(view); } } diff --git a/packages/ember-glimmer/lib/syntax/-text-area.ts b/packages/ember-glimmer/lib/syntax/-text-area.ts index 7a034c9cd5b..634bc7ef4de 100644 --- a/packages/ember-glimmer/lib/syntax/-text-area.ts +++ b/packages/ember-glimmer/lib/syntax/-text-area.ts @@ -1,7 +1,7 @@ import { wrapComponentClassAttribute } from '../utils/bindings'; import { hashToArgs } from './utils'; -export function textAreaMacro(name, params, hash, builder) { +export function textAreaMacro(_name, params, hash, builder) { let definition = builder.env.getComponentDefinition('-text-area', builder.meta.templateMeta); wrapComponentClassAttribute(hash); builder.component.static(definition, [params, hashToArgs(hash), null, null]); diff --git a/packages/ember-glimmer/lib/syntax/dynamic-component.ts b/packages/ember-glimmer/lib/syntax/dynamic-component.ts index ef1a30ea6b1..9f9c512584c 100644 --- a/packages/ember-glimmer/lib/syntax/dynamic-component.ts +++ b/packages/ember-glimmer/lib/syntax/dynamic-component.ts @@ -11,7 +11,7 @@ function dynamicComponentFor(vm, args, meta) { return new DynamicComponentReference({ nameRef, env, meta, args: null }); } -export function dynamicComponentMacro(params, hash, _default, inverse, builder) { +export function dynamicComponentMacro(params, hash, _default, _inverse, builder) { let definitionArgs = [params.slice(0, 1), null, null, null]; let args = [params.slice(1), hashToArgs(hash), null, null]; builder.component.dynamic(definitionArgs, dynamicComponentFor, args); @@ -25,7 +25,7 @@ export function blockComponentMacro(params, hash, _default, inverse, builder) { return true; } -export function inlineComponentMacro(name, params, hash, builder) { +export function inlineComponentMacro(_name, params, hash, builder) { let definitionArgs = [params.slice(0, 1), null, null, null]; let args = [params.slice(1), hashToArgs(hash), null, null]; builder.component.dynamic(definitionArgs, dynamicComponentFor, args); @@ -54,6 +54,7 @@ class DynamicComponentReference { if (typeof nameOrDef === 'string') { let definition = env.getComponentDefinition(nameOrDef, meta); + // tslint:disable-next-line:max-line-length assert(`Could not find component named "${nameOrDef}" (no component or template with that name was found)`, definition); return definition; @@ -64,6 +65,5 @@ class DynamicComponentReference { } } - get() { - } + get() { /* NOOP */ } } diff --git a/packages/ember-glimmer/lib/syntax/input.ts b/packages/ember-glimmer/lib/syntax/input.ts index 80313a3a613..4fba85e65ab 100644 --- a/packages/ember-glimmer/lib/syntax/input.ts +++ b/packages/ember-glimmer/lib/syntax/input.ts @@ -148,7 +148,7 @@ function buildSyntax(type, params, hash, builder) { @public */ -export function inputMacro(name, params, hash, builder) { +export function inputMacro(_name, params, hash, builder) { let keys; let values; let typeIndex = -1; diff --git a/packages/ember-glimmer/lib/syntax/mount.ts b/packages/ember-glimmer/lib/syntax/mount.ts index ef9d28448fb..0dbe9b5005a 100644 --- a/packages/ember-glimmer/lib/syntax/mount.ts +++ b/packages/ember-glimmer/lib/syntax/mount.ts @@ -2,7 +2,6 @@ @module ember */ import { assert } from 'ember-debug'; -import { DEBUG } from 'ember-env-flags'; import { EMBER_ENGINES_MOUNT_PARAMS } from 'ember/features'; import { MountDefinition } from '../component-managers/mount'; import { hashToArgs } from './utils'; @@ -55,7 +54,7 @@ function dynamicEngineFor(vm, args, meta) { @category ember-application-engines @public */ -export function mountMacro(name, params, hash, builder) { +export function mountMacro(_name, params, hash, builder) { if (EMBER_ENGINES_MOUNT_PARAMS) { assert( 'You can only pass a single positional argument to the {{mount}} helper, e.g. {{mount "chat-engine"}}.', diff --git a/packages/ember-glimmer/lib/syntax/outlet.ts b/packages/ember-glimmer/lib/syntax/outlet.ts index e99a726ef0e..4e7c1cc9313 100644 --- a/packages/ember-glimmer/lib/syntax/outlet.ts +++ b/packages/ember-glimmer/lib/syntax/outlet.ts @@ -128,7 +128,7 @@ function outletComponentFor(vm, args) { @for Ember.Templates.helpers @public */ -export function outletMacro(name, params, hash, builder) { +export function outletMacro(_name, params, _hash, builder) { if (!params) { params = []; } diff --git a/packages/ember-glimmer/lib/syntax/render.ts b/packages/ember-glimmer/lib/syntax/render.ts index 87cbef380f7..a10ac6ea1fc 100644 --- a/packages/ember-glimmer/lib/syntax/render.ts +++ b/packages/ember-glimmer/lib/syntax/render.ts @@ -16,10 +16,12 @@ function makeComponentDefinition(vm, args) { let nameRef = args.positional.at(0); assert(`The first argument of {{render}} must be quoted, e.g. {{render "sidebar"}}.`, isConst(nameRef)); + // tslint:disable-next-line:max-line-length assert(`The second argument of {{render}} must be a path, e.g. {{render "post" post}}.`, args.positional.length === 1 || !isConst(args.positional.at(1))); let templateName = nameRef.value(); + // tslint:disable-next-line:max-line-length assert(`You used \`{{render '${templateName}'}}\`, but '${templateName}' can not be found as a template.`, env.owner.hasRegistration(`template:${templateName}`)); let template = env.owner.lookup(`template:${templateName}`); @@ -29,10 +31,12 @@ function makeComponentDefinition(vm, args) { if (args.named.has('controller')) { let controllerNameRef = args.named.get('controller'); + // tslint:disable-next-line:max-line-length assert(`The controller argument for {{render}} must be quoted, e.g. {{render "sidebar" controller="foo"}}.`, isConst(controllerNameRef)); controllerName = controllerNameRef.value(); + // tslint:disable-next-line:max-line-length assert(`The controller name you supplied '${controllerName}' did not resolve to a controller.`, env.owner.hasRegistration(`controller:${controllerName}`)); } else { controllerName = templateName; @@ -117,7 +121,7 @@ function makeComponentDefinition(vm, args) { @public @deprecated Use a component instead */ -export function renderMacro(name, params, hash, builder) { +export function renderMacro(_name, params, hash, builder) { if (!params) { params = []; } diff --git a/packages/ember-glimmer/lib/utils/iterable.ts b/packages/ember-glimmer/lib/utils/iterable.ts index ba82dd2274f..f1a72cb35bb 100644 --- a/packages/ember-glimmer/lib/utils/iterable.ts +++ b/packages/ember-glimmer/lib/utils/iterable.ts @@ -54,8 +54,8 @@ function keyForArray(keyPath) { } } -function index(item, index) { - return String(index); +function index(_item, i) { + return String(i); } function identity(item) { @@ -249,7 +249,7 @@ class ArrayIterable { return get(iterable, 'length') > 0 ? new EmberArrayIterator(iterable, keyFor) : EMPTY_ITERATOR; } else if (typeof iterable.forEach === 'function') { let array: any[] = []; - iterable.forEach(function(item) { + iterable.forEach((item) => { array.push(item); }); return array.length > 0 ? new ArrayIterator(array, keyFor) : EMPTY_ITERATOR; diff --git a/packages/ember-glimmer/lib/utils/references.ts b/packages/ember-glimmer/lib/utils/references.ts index 2dd02ae0a21..0d45e87c9fa 100644 --- a/packages/ember-glimmer/lib/utils/references.ts +++ b/packages/ember-glimmer/lib/utils/references.ts @@ -6,7 +6,6 @@ import { isConst, TagWrapper, UpdatableTag, - VersionedPathReference, } from '@glimmer/reference'; import { ConditionalReference as GlimmerConditionalReference, @@ -24,7 +23,6 @@ import { } from 'ember-metal'; import { HAS_NATIVE_WEAKMAP, - Opaque, symbol, } from 'ember-utils'; import { @@ -76,7 +74,7 @@ export class CachedReference extends EmberPathReference { this._lastValue = null; } - compute() {} + compute() { /* NOOP */ } value() { let { tag, _lastRevision, _lastValue } = this; diff --git a/tsconfig.json b/tsconfig.json index 94a6020c589..1922bcffbf1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,8 +16,8 @@ // Enhance Strictness // "noImplicitAny": true, // "suppressImplicitAnyIndexErrors": true, - // "noUnusedLocals": true, - // "noUnusedParameters": true, + "noUnusedLocals": true, + "noUnusedParameters": true, // "allowUnreachableCode": false, // "strictNullChecks": true, // "noImplicitReturns": true, @@ -33,7 +33,7 @@ }, "files": [ + "packages/ember-glimmer/externs.d.ts", "packages/ember-glimmer/lib/index.ts" ] - } From da1eda79e946761a958b22c662e3ddf4ca1b53d8 Mon Sep 17 00:00:00 2001 From: Kris Selden Date: Wed, 25 Oct 2017 18:27:56 -0700 Subject: [PATCH 18/24] fix custom component manager test --- .../tests/integration/custom-component-manager-test.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/ember-glimmer/tests/integration/custom-component-manager-test.js b/packages/ember-glimmer/tests/integration/custom-component-manager-test.js index 7ceb957279c..6c94c60be67 100644 --- a/packages/ember-glimmer/tests/integration/custom-component-manager-test.js +++ b/packages/ember-glimmer/tests/integration/custom-component-manager-test.js @@ -41,6 +41,14 @@ if (GLIMMER_CUSTOM_COMPONENT_MANAGER) { layoutFor(definition, bucket, env) { return env.getCompiledBlock(TestLayoutCompiler, definition.template); } + + getDestructor(component) { + return component; + } + + getSelf() { + return null; + } } moduleFor('Components test: curly components with custom manager', class extends RenderingTest { From d3326e56bcaffd35bee39400f180518138b17920 Mon Sep 17 00:00:00 2001 From: Kris Selden Date: Wed, 25 Oct 2017 19:44:24 -0700 Subject: [PATCH 19/24] Add stricter typing --- packages/ember-glimmer/lib/environment.ts | 34 ++++++++++++++++++----- packages/ember-glimmer/lib/template.ts | 4 ++- packages/ember-metal/lib/index.d.ts | 8 +++--- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/packages/ember-glimmer/lib/environment.ts b/packages/ember-glimmer/lib/environment.ts index 4de2f712939..1c4d3687a11 100644 --- a/packages/ember-glimmer/lib/environment.ts +++ b/packages/ember-glimmer/lib/environment.ts @@ -3,6 +3,8 @@ import { } from '@glimmer/reference'; import { AttributeManager, + CompilableLayout, + CompiledDynamicProgram, compileLayout, Environment as GlimmerEnvironment, getDynamicVar, @@ -64,12 +66,21 @@ import { EMBER_MODULE_UNIFICATION, GLIMMER_CUSTOM_COMPONENT_MANAGER, } from 'ember/features'; -import { Container } from './template'; +import { Container, OwnedTemplate, WrappedTemplateFactory } from './template'; function instrumentationPayload(name) { return { object: `component:${name}` }; } +function isTemplateFactory(template: OwnedTemplate | WrappedTemplateFactory): template is WrappedTemplateFactory { + return typeof (template as WrappedTemplateFactory).create === 'function'; +} + +export interface CompilerFactory { + id: string; + new (template: OwnedTemplate): CompilableLayout; +} + export default class Environment extends GlimmerEnvironment { static create(options) { return new this(options); @@ -86,9 +97,16 @@ export default class Environment extends GlimmerEnvironment { }; public debugStack: typeof DebugStack; public inTransaction: boolean; - private _definitionCache: Cache; - private _templateCache: Cache; - private _compilerCache: Cache; + private _definitionCache: Cache<{ + name: string; + source: string; + owner: Container; + }, CurlyComponentDefinition | undefined>; + private _templateCache: Cache<{ + Template: WrappedTemplateFactory | OwnedTemplate; + owner: Container; + }, OwnedTemplate>; + private _compilerCache: Cache>; constructor(injections: any) { super(injections); @@ -102,18 +120,20 @@ export default class Environment extends GlimmerEnvironment { this._definitionCache = new Cache(2000, ({ name, source, owner }) => { let { component: componentFactory, layout } = lookupComponent(owner, name, { source }); - let customManager; + let customManager: any; if (componentFactory || layout) { if (GLIMMER_CUSTOM_COMPONENT_MANAGER) { let managerId = layout && layout.meta.managerId; if (managerId) { - customManager = owner.factoryFor(`component-manager:${managerId}`).class; + customManager = owner.factoryFor(`component-manager:${managerId}`).class; } } return new CurlyComponentDefinition(name, componentFactory, layout, undefined, customManager); } + + return undefined; }, ({ name, source, owner }) => { let expandedName = source && this._resolveLocalLookupName(name, source, owner) || name; @@ -123,7 +143,7 @@ export default class Environment extends GlimmerEnvironment { }); this._templateCache = new Cache(1000, ({ Template, owner }) => { - if (Template.create) { + if (isTemplateFactory(Template)) { // we received a factory return Template.create({ env: this, [OWNER]: owner }); } else { diff --git a/packages/ember-glimmer/lib/template.ts b/packages/ember-glimmer/lib/template.ts index d58fda7906f..0a2486c70c7 100644 --- a/packages/ember-glimmer/lib/template.ts +++ b/packages/ember-glimmer/lib/template.ts @@ -7,6 +7,7 @@ import { OWNER } from 'ember-utils'; export interface Container { lookup(name: string): T; + factoryFor(name: string): T; } export type OwnedTemplate = Template<{ @@ -14,11 +15,12 @@ export type OwnedTemplate = Template<{ owner: Container; }>; -class WrappedTemplateFactory { +export class WrappedTemplateFactory { id: string; meta: { moduleName: string; }; + constructor(public factory: TemplateFactory<{ moduleName: string; }, { diff --git a/packages/ember-metal/lib/index.d.ts b/packages/ember-metal/lib/index.d.ts index 5f857c05dfd..7f814ab3df7 100644 --- a/packages/ember-metal/lib/index.d.ts +++ b/packages/ember-metal/lib/index.d.ts @@ -41,7 +41,7 @@ export function watchKey(obj: any, keyName: string, meta?: any): void; export function isProxy(value: any): boolean; -export class Cache { - constructor(limit: number, func: (obj: any) => any, key: any, store?: any) - get(obj): any -} \ No newline at end of file +export class Cache { + constructor(limit: number, func: (obj: T) => V, key?: (obj: T) => string, store?: any) + get(obj: T): V +} From 7924d5811fa50bdb19cc6c83937fa35337b7dd53 Mon Sep 17 00:00:00 2001 From: Kris Selden Date: Wed, 25 Oct 2017 22:47:30 -0700 Subject: [PATCH 20/24] more strict flags turned on --- .../lib/component-managers/curly.ts | 25 +++++++++---------- packages/ember-glimmer/lib/component.ts | 9 +++++-- .../ember-glimmer/lib/components/link-to.ts | 23 +++++++++-------- .../ember-glimmer/lib/modifiers/action.ts | 3 ++- packages/ember-glimmer/lib/utils/bindings.ts | 4 ++- .../ember-glimmer/lib/utils/debug-stack.ts | 7 +++--- tsconfig.json | 4 +-- 7 files changed, 42 insertions(+), 33 deletions(-) diff --git a/packages/ember-glimmer/lib/component-managers/curly.ts b/packages/ember-glimmer/lib/component-managers/curly.ts index 901883a5a58..7afcbc03530 100644 --- a/packages/ember-glimmer/lib/component-managers/curly.ts +++ b/packages/ember-glimmer/lib/component-managers/curly.ts @@ -39,6 +39,7 @@ const DEFAULT_LAYOUT = P`template:components/-default`; function aliasIdToElementId(args, props) { if (args.named.has('id')) { + // tslint:disable-next-line:max-line-length assert(`You cannot invoke a component with both 'id' and 'elementId' at the same time.`, !args.named.has('elementId')); props.elementId = props.id; } @@ -74,6 +75,7 @@ function applyAttributeBindings(element, attributeBindings, component, operation } function tagName(vm) { + // tslint:disable-next-line:no-shadowed-variable let { tagName } = vm.dynamicScope().view; return PrimitiveReference.create(tagName === '' ? null : tagName || 'div'); @@ -128,7 +130,8 @@ export default class CurlyComponentManager extends AbstractManager 0; + let componentHasPositionalParams = componentHasRestStylePositionalParams || + componentPositionalParamsDefinition.length > 0; let needsPositionalParamMunging = componentHasPositionalParams && args.positional.length !== 0; let isClosureComponent = definition.args; @@ -370,6 +373,7 @@ export function validatePositionalParameters(named, positional, positionalParams let paramType = typeof positionalParamsDefinition; if (paramType === 'string') { + // tslint:disable-next-line:max-line-length assert(`You cannot specify positional parameters and the hash argument \`${positionalParamsDefinition}\`.`, !named.has(positionalParamsDefinition)); } else { if (positional.length < positionalParamsDefinition.length) { @@ -400,20 +404,15 @@ export function processComponentInitializationAssertions(component, props) { return true; })()); - assert('You cannot use `classNameBindings` on a tag-less component: ' + component.toString(), (() => { - let { classNameBindings, tagName } = component; - return tagName !== '' || !classNameBindings || classNameBindings.length === 0; - })()); + assert('You cannot use `classNameBindings` on a tag-less component: ' + component.toString(), + component.tagName !== '' || !component.classNameBindings || component.classNameBindings.length === 0); - assert('You cannot use `elementId` on a tag-less component: ' + component.toString(), (() => { - let { elementId, tagName } = component; - return tagName !== '' || props.id === elementId || (!elementId && elementId !== ''); - })()); + assert('You cannot use `elementId` on a tag-less component: ' + component.toString(), + component.tagName !== '' || props.id === component.elementId || + (!component.elementId && component.elementId !== '')); - assert('You cannot use `attributeBindings` on a tag-less component: ' + component.toString(), (() => { - let { attributeBindings, tagName } = component; - return tagName !== '' || !attributeBindings || attributeBindings.length === 0; - })()); + assert('You cannot use `attributeBindings` on a tag-less component: ' + component.toString(), + component.tagName !== '' || !component.attributeBindings || component.attributeBindings.length === 0); } export function initialRenderInstrumentDetails(component) { diff --git a/packages/ember-glimmer/lib/component.ts b/packages/ember-glimmer/lib/component.ts index 5a803347758..a96364791eb 100644 --- a/packages/ember-glimmer/lib/component.ts +++ b/packages/ember-glimmer/lib/component.ts @@ -590,11 +590,13 @@ const Component = CoreView.extend( // If in a tagless component, assert that no event handlers are defined assert( + // tslint:disable-next-line:max-line-length `You can not define a function that handles DOM events in the \`${this}\` tagless component since it doesn't have any DOM element.`, this.tagName !== '' || !this.renderer._destinedForDOM || !(() => { let eventDispatcher = getOwner(this).lookup('event_dispatcher:main'); let events = (eventDispatcher && eventDispatcher._finalEvents) || {}; + // tslint:disable-next-line:forin for (let key in events) { let methodName = events[key]; @@ -602,9 +604,11 @@ const Component = CoreView.extend( return true; // indicate that the assertion should be triggered } } + return false; } )()); + // tslint:disable-next-line:max-line-length assert(`You cannot use a computed property for the component's \`tagName\` (${this}).`, !(this.tagName && this.tagName.isDescriptor)); }, @@ -620,9 +624,10 @@ const Component = CoreView.extend( [PROPERTY_DID_CHANGE](key) { if (this[IS_DISPATCHING_ATTRS]) { return; } - let args, reference; + let args = this[ARGS]; + let reference = args && args[key]; - if ((args = this[ARGS]) && (reference = args[key])) { + if (reference) { if (reference[UPDATE]) { reference[UPDATE](get(this, key)); } diff --git a/packages/ember-glimmer/lib/components/link-to.ts b/packages/ember-glimmer/lib/components/link-to.ts index 584ce23c057..1092002024d 100644 --- a/packages/ember-glimmer/lib/components/link-to.ts +++ b/packages/ember-glimmer/lib/components/link-to.ts @@ -592,20 +592,20 @@ const LinkComponent = EmberComponent.extend({ @property active @private */ - active: computed('attrs.params', '_active', function computeLinkToComponentActiveClass() { + active: computed('attrs.params', '_active', function computeLinkToComponentActiveClass(this: any) { let currentState = get(this, '_routing.currentState'); if (!currentState) { return false; } return this.get('_active') ? get(this, 'activeClass') : false; }), - _active: computed('_routing.currentState', function computeLinkToComponentActive() { + _active: computed('_routing.currentState', function computeLinkToComponentActive(this: any) { let currentState = get(this, '_routing.currentState'); if (!currentState) { return false; } return this._isActive(currentState); }), - willBeActive: computed('_routing.targetState', function computeLinkToComponentWillBeActive() { + willBeActive: computed('_routing.targetState', function computeLinkToComponentWillBeActive(this: any) { let routing = get(this, '_routing'); let targetState = get(routing, 'targetState'); if (get(routing, 'currentState') === targetState) { return; } @@ -613,7 +613,7 @@ const LinkComponent = EmberComponent.extend({ return this._isActive(targetState); }), - transitioningIn: computed('active', 'willBeActive', function computeLinkToComponentTransitioningIn() { + transitioningIn: computed('active', 'willBeActive', function computeLinkToComponentTransitioningIn(this: any) { if (get(this, 'willBeActive') === true && !get(this, '_active')) { return 'ember-transitioning-in'; } else { @@ -621,7 +621,7 @@ const LinkComponent = EmberComponent.extend({ } }), - transitioningOut: computed('active', 'willBeActive', function computeLinkToComponentTransitioningOut() { + transitioningOut: computed('active', 'willBeActive', function computeLinkToComponentTransitioningOut(this: any) { if (get(this, 'willBeActive') === false && get(this, '_active')) { return 'ember-transitioning-out'; } else { @@ -636,7 +636,7 @@ const LinkComponent = EmberComponent.extend({ @param {Event} event @private */ - _invoke(event) { + _invoke(this: any, event: Event): boolean { if (!isSimpleClick(event)) { return true; } let preventDefault = get(this, 'preventDefault'); @@ -674,6 +674,7 @@ const LinkComponent = EmberComponent.extend({ // tslint:disable-next-line:max-line-length flaggedInstrument('interaction.link-to', payload, this._generateTransition(payload, qualifiedRouteName, models, queryParams, shouldReplace)); + return false; }, _generateTransition(payload, qualifiedRouteName, models, queryParams, shouldReplace) { @@ -686,7 +687,7 @@ const LinkComponent = EmberComponent.extend({ queryParams: null, qualifiedRouteName: computed('targetRouteName', '_routing.currentState', - function computeLinkToComponentQualifiedRouteName() { + function computeLinkToComponentQualifiedRouteName(this: any) { let params = get(this, 'params'); let paramsLength = params.length; let lastParam = params[paramsLength - 1]; @@ -700,7 +701,7 @@ const LinkComponent = EmberComponent.extend({ return get(this, 'targetRouteName'); }), - resolvedQueryParams: computed('queryParams', function computeLinkToComponentResolvedQueryParams() { + resolvedQueryParams: computed('queryParams', function computeLinkToComponentResolvedQueryParams(this: any) { let resolvedQueryParams = {}; let queryParams = get(this, 'queryParams'); @@ -725,7 +726,7 @@ const LinkComponent = EmberComponent.extend({ @property href @private */ - href: computed('models', 'qualifiedRouteName', function computeLinkToComponentHref() { + href: computed('models', 'qualifiedRouteName', function computeLinkToComponentHref(this: any) { if (get(this, 'tagName') !== 'a') { return; } let qualifiedRouteName = get(this, 'qualifiedRouteName'); @@ -759,7 +760,7 @@ const LinkComponent = EmberComponent.extend({ return routing.generateURL(qualifiedRouteName, models, queryParams); }), - loading: computed('_modelsAreLoaded', 'qualifiedRouteName', function computeLinkToComponentLoading() { + loading: computed('_modelsAreLoaded', 'qualifiedRouteName', function computeLinkToComponentLoading(this: any) { let qualifiedRouteName = get(this, 'qualifiedRouteName'); let modelsAreLoaded = get(this, '_modelsAreLoaded'); @@ -768,7 +769,7 @@ const LinkComponent = EmberComponent.extend({ } }), - _modelsAreLoaded: computed('models', function computeLinkToComponentModelsAreLoaded() { + _modelsAreLoaded: computed('models', function computeLinkToComponentModelsAreLoaded(this: any) { let models = get(this, 'models'); for (let i = 0; i < models.length; i++) { if (models[i] == null) { return false; } diff --git a/packages/ember-glimmer/lib/modifiers/action.ts b/packages/ember-glimmer/lib/modifiers/action.ts index b2bf5fd2965..d68a54830ce 100644 --- a/packages/ember-glimmer/lib/modifiers/action.ts +++ b/packages/ember-glimmer/lib/modifiers/action.ts @@ -102,7 +102,7 @@ export class ActionState { return target; } - handler(event) { + handler(event): boolean { let { actionName, namedArgs } = this; let bubbles = namedArgs.get('bubbles'); let preventDefault = namedArgs.get('preventDefault'); @@ -155,6 +155,7 @@ export class ActionState { }); } }); + return false; } destroy() { diff --git a/packages/ember-glimmer/lib/utils/bindings.ts b/packages/ember-glimmer/lib/utils/bindings.ts index dd34df2e8cc..63afc0f4cad 100644 --- a/packages/ember-glimmer/lib/utils/bindings.ts +++ b/packages/ember-glimmer/lib/utils/bindings.ts @@ -190,7 +190,9 @@ class SimpleClassNameBindingReference extends CachedReference> { class ColonClassNameBindingReference extends CachedReference> { public tag: Tag; - constructor(private inner: Reference, private truthy: Option = null, private falsy: Option = null) { + constructor(private inner: Reference, + private truthy: Option = null, + private falsy: Option = null) { super(); this.tag = inner.tag; diff --git a/packages/ember-glimmer/lib/utils/debug-stack.ts b/packages/ember-glimmer/lib/utils/debug-stack.ts index d527b0b4fe8..0ff4e0f175f 100644 --- a/packages/ember-glimmer/lib/utils/debug-stack.ts +++ b/packages/ember-glimmer/lib/utils/debug-stack.ts @@ -13,6 +13,7 @@ if (DEBUG) { class TemplateElement extends Element { } class EngineElement extends Element { } + // tslint:disable-next-line:no-shadowed-variable DebugStack = class DebugStack { private _stack: TemplateElement[] = []; @@ -24,7 +25,7 @@ if (DEBUG) { this._stack.push(new EngineElement(name)); } - pop() { + pop(): string | void { let element = this._stack.pop(); if (element) { @@ -32,7 +33,7 @@ if (DEBUG) { } } - peek() { + peek(): string | void { let template = this._currentTemplate(); let engine = this._currentEngine(); @@ -51,7 +52,7 @@ if (DEBUG) { return this._getCurrentByType(EngineElement); } - _getCurrentByType(type) { + _getCurrentByType(type): string | void { for (let i = this._stack.length; i >= 0; i--) { let element = this._stack[i]; if (element instanceof type) { diff --git a/tsconfig.json b/tsconfig.json index 1922bcffbf1..28dbdab8069 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -20,8 +20,8 @@ "noUnusedParameters": true, // "allowUnreachableCode": false, // "strictNullChecks": true, - // "noImplicitReturns": true, - // "noImplicitThis": true, + "noImplicitReturns": true, + "noImplicitThis": true, "newLine": "LF", "noEmit": true, From b431c7ce164e71993b76192f69d9048ae54e289d Mon Sep 17 00:00:00 2001 From: Kris Selden Date: Wed, 25 Oct 2017 23:08:04 -0700 Subject: [PATCH 21/24] curious if this works --- testem.dist.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testem.dist.json b/testem.dist.json index 411da31de1d..4dbcabd7b6c 100644 --- a/testem.dist.json +++ b/testem.dist.json @@ -22,7 +22,7 @@ "protocol": "tap" }, "SL_MS_Edge": { - "command": "npm run sauce:launch -- -p 'Windows 10' -b 'microsoftedge' -v latest --no-connect -u ''", + "command": "npm run sauce:launch -- -p 'Windows 10' -b 'microsoftedge' -v 14 --no-connect -u ''", "protocol": "tap" }, "SL_IE_11": { From 809720f8dd5dc305f76becb70d7738de99fcdcde Mon Sep 17 00:00:00 2001 From: Kris Selden Date: Thu, 26 Oct 2017 01:12:08 -0700 Subject: [PATCH 22/24] add strict null checking --- .../lib/component-managers/outlet.ts | 14 +-- .../lib/component-managers/render.ts | 2 +- packages/ember-glimmer/lib/environment.ts | 28 +++--- packages/ember-glimmer/lib/helpers/action.ts | 17 ++-- .../ember-glimmer/lib/helpers/component.ts | 6 +- .../ember-glimmer/lib/modifiers/action.ts | 2 +- packages/ember-glimmer/lib/renderer.ts | 46 +++++----- .../lib/templates/component.d.ts | 3 +- .../ember-glimmer/lib/templates/empty.d.ts | 3 +- .../ember-glimmer/lib/templates/link-to.d.ts | 3 +- .../ember-glimmer/lib/templates/outlet.d.ts | 3 +- .../ember-glimmer/lib/templates/root.d.ts | 3 +- packages/ember-glimmer/lib/views/outlet.ts | 85 ++++++++++--------- .../tests/integration/outlet-test.js | 15 ---- packages/ember-routing/lib/system/route.js | 2 - tests/node/helpers/component-module.js | 4 +- tsconfig.json | 2 +- 17 files changed, 122 insertions(+), 116 deletions(-) diff --git a/packages/ember-glimmer/lib/component-managers/outlet.ts b/packages/ember-glimmer/lib/component-managers/outlet.ts index cb46f4a7a9e..eb0b213b08d 100644 --- a/packages/ember-glimmer/lib/component-managers/outlet.ts +++ b/packages/ember-glimmer/lib/component-managers/outlet.ts @@ -1,13 +1,14 @@ -import { Option } from '@glimmer/interfaces/dist/types'; +import { Option } from '@glimmer/interfaces'; import { ComponentDefinition, DynamicScope, + Environment, } from '@glimmer/runtime'; import { Destroyable } from '@glimmer/util/dist/types'; import { DEBUG } from 'ember-env-flags'; -import { Environment } from 'ember-glimmer'; import { _instrumentStart } from 'ember-metal'; import { generateGuid, guidFor } from 'ember-utils'; +import EmberEnvironment from '../environment'; import { RootReference } from '../utils/references'; import AbstractManager from './abstract'; @@ -42,7 +43,10 @@ class StateBucket { } class OutletComponentManager extends AbstractManager { - create(environment: Environment, definition: OutletComponentDefinition, _args, dynamicScope: OutletDynamicScope) { + create(environment: Environment, + definition: OutletComponentDefinition, + _args, + dynamicScope: OutletDynamicScope) { if (DEBUG) { this._pushToDebugStack(`template:${definition.template.meta.moduleName}`, environment); } @@ -54,7 +58,7 @@ class OutletComponentManager extends AbstractManager { } layoutFor(definition, _bucket, env: Environment) { - return env.getCompiledBlock(OutletLayoutCompiler, definition.template); + return (env as EmberEnvironment).getCompiledBlock(OutletLayoutCompiler, definition.template); } getSelf({ outletState }) { @@ -117,7 +121,7 @@ class TopLevelOutletLayoutCompiler { TopLevelOutletLayoutCompiler.id = 'top-level-outlet'; -export class OutletComponentDefinition extends ComponentDefinition { +export class OutletComponentDefinition extends ComponentDefinition { public outletName: string; public template: any; diff --git a/packages/ember-glimmer/lib/component-managers/render.ts b/packages/ember-glimmer/lib/component-managers/render.ts index b6b929ac06a..4c05b9e8aef 100644 --- a/packages/ember-glimmer/lib/component-managers/render.ts +++ b/packages/ember-glimmer/lib/component-managers/render.ts @@ -38,7 +38,7 @@ class SingletonRenderManager extends AbstractRenderManager { _args: IArguments, dynamicScope: DynamicScope) { let { name } = definition; - let controller = env.owner.lookup(`controller:${name}`) || generateController(env.owner, name); + let controller = env.owner.lookup(`controller:${name}`) || generateController(env.owner, name); if (DEBUG) { this._pushToDebugStack(`controller:${name} (with the render helper)`, env); diff --git a/packages/ember-glimmer/lib/environment.ts b/packages/ember-glimmer/lib/environment.ts index 1c4d3687a11..ade59e95ca8 100644 --- a/packages/ember-glimmer/lib/environment.ts +++ b/packages/ember-glimmer/lib/environment.ts @@ -6,9 +6,12 @@ import { CompilableLayout, CompiledDynamicProgram, compileLayout, + ComponentDefinition, Environment as GlimmerEnvironment, getDynamicVar, + Helper, isSafeString, + ModifierManager, PartialDefinition, } from '@glimmer/runtime'; import { @@ -90,10 +93,10 @@ export default class Environment extends GlimmerEnvironment { public isInteractive: boolean; public destroyedComponents: Destroyable[]; public builtInModifiers: { - [name: string]: any; + [name: string]: ModifierManager; }; public builtInHelpers: { - [name: string]: any; + [name: string]: Helper; }; public debugStack: typeof DebugStack; public inTransaction: boolean; @@ -101,7 +104,7 @@ export default class Environment extends GlimmerEnvironment { name: string; source: string; owner: Container; - }, CurlyComponentDefinition | undefined>; + }, CurlyComponentDefinition>; private _templateCache: Cache<{ Template: WrappedTemplateFactory | OwnedTemplate; owner: Container; @@ -121,19 +124,14 @@ export default class Environment extends GlimmerEnvironment { this._definitionCache = new Cache(2000, ({ name, source, owner }) => { let { component: componentFactory, layout } = lookupComponent(owner, name, { source }); let customManager: any; + if (GLIMMER_CUSTOM_COMPONENT_MANAGER) { + let managerId = layout && layout.meta.managerId; - if (componentFactory || layout) { - if (GLIMMER_CUSTOM_COMPONENT_MANAGER) { - let managerId = layout && layout.meta.managerId; - - if (managerId) { - customManager = owner.factoryFor(`component-manager:${managerId}`).class; - } + if (managerId) { + customManager = owner.factoryFor(`component-manager:${managerId}`).class; } - return new CurlyComponentDefinition(name, componentFactory, layout, undefined, customManager); } - - return undefined; + return new CurlyComponentDefinition(name, componentFactory, layout, undefined, customManager); }, ({ name, source, owner }) => { let expandedName = source && this._resolveLocalLookupName(name, source, owner) || name; @@ -213,7 +211,7 @@ export default class Environment extends GlimmerEnvironment { return false; } - getComponentDefinition(name, { owner, moduleName }) { + getComponentDefinition(name, { owner, moduleName }): ComponentDefinition { let finalizer = _instrumentStart('render.getComponentDefinition', instrumentationPayload, name); let source = moduleName && `template:${moduleName}`; let definition = this._definitionCache.get({ name, source, owner }); @@ -262,7 +260,7 @@ export default class Environment extends GlimmerEnvironment { owner.hasRegistration(`helper:${name}`); } - lookupHelper(name, meta) { + lookupHelper(name, meta): Helper { if (name === 'component') { return (vm, args) => componentHelper(vm, args, meta); } diff --git a/packages/ember-glimmer/lib/helpers/action.ts b/packages/ember-glimmer/lib/helpers/action.ts index 9de1bf243ba..286049d2231 100644 --- a/packages/ember-glimmer/lib/helpers/action.ts +++ b/packages/ember-glimmer/lib/helpers/action.ts @@ -1,7 +1,9 @@ /** @module ember */ -import { isConst } from '@glimmer/reference'; +import { isConst, VersionedPathReference } from '@glimmer/reference'; +import { IArguments } from '@glimmer/runtime/dist/types/lib/vm/arguments'; +import { Opaque } from '@glimmer/util'; import { assert } from 'ember-debug'; import { DEBUG } from 'ember-env-flags'; import { @@ -270,7 +272,7 @@ export const ACTION = symbol('ACTION'); @for Ember.Templates.helpers @public */ -export default function(_vm, args): UnboundReference { +export default function(_vm, args: IArguments): UnboundReference { let { named, positional } = args; let capturedArgs = positional.capture(); @@ -282,7 +284,7 @@ export default function(_vm, args): UnboundReference { let [context, action, ...restArgs] = capturedArgs.references; // TODO: Is there a better way of doing this? - let debugKey = action._propertyKey; + let debugKey: string | undefined = (action as any)._propertyKey; let target = named.has('target') ? named.get('target') : context; let processArgs = makeArgsProcessor(named.has('value') && named.get('value'), restArgs); @@ -304,8 +306,9 @@ export default function(_vm, args): UnboundReference { function NOOP(args) { return args; } -function makeArgsProcessor(valuePathRef, actionArgsRef) { - let mergeArgs = null; +function makeArgsProcessor(valuePathRef: VersionedPathReference | false, + actionArgsRef: Array>) { + let mergeArgs; if (actionArgsRef.length > 0) { mergeArgs = (args) => { @@ -313,14 +316,14 @@ function makeArgsProcessor(valuePathRef, actionArgsRef) { }; } - let readValue = null; + let readValue; if (valuePathRef) { readValue = (args) => { let valuePath = valuePathRef.value(); if (valuePath && args.length > 0) { - args[0] = get(args[0], valuePath); + args[0] = get(args[0], valuePath as string); } return args; diff --git a/packages/ember-glimmer/lib/helpers/component.ts b/packages/ember-glimmer/lib/helpers/component.ts index ebf5667fd4f..a5dadeba442 100644 --- a/packages/ember-glimmer/lib/helpers/component.ts +++ b/packages/ember-glimmer/lib/helpers/component.ts @@ -154,7 +154,7 @@ export class ClosureComponentReference extends CachedReference { public meta: any; public env: any; public lastDefinition: any; - public lastName: string; + public lastName: string | undefined; constructor(args, meta, env) { super(); @@ -175,7 +175,7 @@ export class ClosureComponentReference extends CachedReference { // currying are in the assertion messages. let { args, defRef, env, meta, lastDefinition, lastName } = this; let nameOrDef = defRef.value(); - let definition = null; + let definition; if (nameOrDef && nameOrDef === lastName) { return lastDefinition; @@ -192,7 +192,7 @@ export class ClosureComponentReference extends CachedReference { definition = env.getComponentDefinition(nameOrDef, meta); // tslint:disable-next-line:max-line-length - assert(`The component helper cannot be used without a valid component name. You used "${nameOrDef}" via (component "${nameOrDef}")`, definition); + assert(`The component helper cannot be used without a valid component name. You used "${nameOrDef}" via (component "${nameOrDef}")`, !!definition); } else if (isComponentDefinition(nameOrDef)) { definition = nameOrDef; } else { diff --git a/packages/ember-glimmer/lib/modifiers/action.ts b/packages/ember-glimmer/lib/modifiers/action.ts index d68a54830ce..57d480894c5 100644 --- a/packages/ember-glimmer/lib/modifiers/action.ts +++ b/packages/ember-glimmer/lib/modifiers/action.ts @@ -190,7 +190,7 @@ export default class ActionModifierManager { } } - let actionArgs = []; + let actionArgs: any[] = []; // The first two arguments are (1) `this` and (2) the action name. // Everything else is a param. for (let i = 2; i < positional.length; i++) { diff --git a/packages/ember-glimmer/lib/renderer.ts b/packages/ember-glimmer/lib/renderer.ts index f3fada0f3d7..edd9ba85a8d 100644 --- a/packages/ember-glimmer/lib/renderer.ts +++ b/packages/ember-glimmer/lib/renderer.ts @@ -1,9 +1,11 @@ -import { Simple } from '@glimmer/interfaces'; +import { Option, Simple } from '@glimmer/interfaces'; import { CURRENT_TAG, VersionedPathReference } from '@glimmer/reference'; -import { IteratorResult } from '@glimmer/runtime'; +import { + DynamicScope as GlimmerDynamicScope, + IteratorResult, +} from '@glimmer/runtime'; import { Opaque } from '@glimmer/util'; import { assert } from 'ember-debug'; -import { Environment } from 'ember-glimmer'; import { run, runInTransaction, @@ -18,19 +20,25 @@ import { import { BOUNDS } from './component'; import { TopLevelOutletComponentDefinition } from './component-managers/outlet'; import { RootComponentDefinition } from './component-managers/root'; +import Environment from './environment'; import { OwnedTemplate } from './template'; import { RootReference } from './utils/references'; -import OutletView, { OutletState, OutletStateReference } from './views/outlet'; +import OutletView, { OutletState, RootOutletStateReference } from './views/outlet'; -import { ComponentDefinition, RenderResult } from '@glimmer/runtime'; +import { ComponentDefinition, NULL_REFERENCE, RenderResult } from '@glimmer/runtime'; const { backburner } = run; -export class DynamicScope { +export class DynamicScope implements GlimmerDynamicScope { + outletState: VersionedPathReference>; + rootOutletState: RootOutletStateReference | undefined; + constructor( public view: Opaque, - public outletState?: VersionedPathReference, - public rootOutletState?: OutletStateReference) { + outletState: VersionedPathReference>, + rootOutletState?: RootOutletStateReference) { + this.outletState = outletState; + this.rootOutletState = rootOutletState; } child() { @@ -39,13 +47,13 @@ export class DynamicScope { ); } - get(key) { + get(key: 'outletState'): VersionedPathReference> { // tslint:disable-next-line:max-line-length assert(`Using \`-get-dynamic-scope\` is only supported for \`outletState\` (you used \`${key}\`).`, key === 'outletState'); return this.outletState; } - set(key, value) { + set(key: 'outletState', value: VersionedPathReference>) { // tslint:disable-next-line:max-line-length assert(`Using \`-with-dynamic-scope\` is only supported for \`outletState\` (you used \`${key}\`).`, key === 'outletState'); this.outletState = value; @@ -57,7 +65,7 @@ class RootState { public id: string; public env: Environment; public root: Opaque; - public result: RenderResult; + public result: RenderResult | undefined; public shouldReflush: boolean; public destroyed: boolean; public options: { @@ -111,10 +119,10 @@ class RootState { this.destroyed = true; - this.env = null; + this.env = undefined as any; this.root = null; - this.result = null; - this.render = null; + this.result = undefined; + this.render = undefined as any; if (result) { /* @@ -142,7 +150,7 @@ class RootState { } } -const renderers: any[] = []; +const renderers: Renderer[] = []; export function _resetRenderers() { renderers.length = 0; @@ -209,7 +217,7 @@ export abstract class Renderer { this._destinedForDOM = destinedForDOM; this._destroyed = false; this._roots = []; - this._lastRevision = null; + this._lastRevision = -1; this._isRenderingRoots = false; this._removedRoots = []; } @@ -233,9 +241,9 @@ export abstract class Renderer { root: Opaque, definition: ComponentDefinition, target: Simple.Element, - outletStateReference?: OutletStateReference) { + outletStateReference?: RootOutletStateReference) { let self = new RootReference(definition); - let dynamicScope = new DynamicScope(null, outletStateReference, outletStateReference); + let dynamicScope = new DynamicScope(null, outletStateReference || NULL_REFERENCE, outletStateReference); let rootState = new RootState(root, this._env, this._rootTemplate, self, target, dynamicScope); this._renderRoot(rootState); @@ -376,7 +384,7 @@ export abstract class Renderer { while (removedRoots.length) { let root = removedRoots.pop(); - let rootIndex = roots.indexOf(root); + let rootIndex = roots.indexOf(root!); roots.splice(rootIndex, 1); } diff --git a/packages/ember-glimmer/lib/templates/component.d.ts b/packages/ember-glimmer/lib/templates/component.d.ts index c800f6734c1..01e88b1186d 100644 --- a/packages/ember-glimmer/lib/templates/component.d.ts +++ b/packages/ember-glimmer/lib/templates/component.d.ts @@ -1,2 +1,3 @@ -declare const TEMPLATE: any; +import { WrappedTemplateFactory } from '../template'; +declare const TEMPLATE: WrappedTemplateFactory; export default TEMPLATE; diff --git a/packages/ember-glimmer/lib/templates/empty.d.ts b/packages/ember-glimmer/lib/templates/empty.d.ts index c800f6734c1..01e88b1186d 100644 --- a/packages/ember-glimmer/lib/templates/empty.d.ts +++ b/packages/ember-glimmer/lib/templates/empty.d.ts @@ -1,2 +1,3 @@ -declare const TEMPLATE: any; +import { WrappedTemplateFactory } from '../template'; +declare const TEMPLATE: WrappedTemplateFactory; export default TEMPLATE; diff --git a/packages/ember-glimmer/lib/templates/link-to.d.ts b/packages/ember-glimmer/lib/templates/link-to.d.ts index c800f6734c1..01e88b1186d 100644 --- a/packages/ember-glimmer/lib/templates/link-to.d.ts +++ b/packages/ember-glimmer/lib/templates/link-to.d.ts @@ -1,2 +1,3 @@ -declare const TEMPLATE: any; +import { WrappedTemplateFactory } from '../template'; +declare const TEMPLATE: WrappedTemplateFactory; export default TEMPLATE; diff --git a/packages/ember-glimmer/lib/templates/outlet.d.ts b/packages/ember-glimmer/lib/templates/outlet.d.ts index c800f6734c1..01e88b1186d 100644 --- a/packages/ember-glimmer/lib/templates/outlet.d.ts +++ b/packages/ember-glimmer/lib/templates/outlet.d.ts @@ -1,2 +1,3 @@ -declare const TEMPLATE: any; +import { WrappedTemplateFactory } from '../template'; +declare const TEMPLATE: WrappedTemplateFactory; export default TEMPLATE; diff --git a/packages/ember-glimmer/lib/templates/root.d.ts b/packages/ember-glimmer/lib/templates/root.d.ts index c800f6734c1..01e88b1186d 100644 --- a/packages/ember-glimmer/lib/templates/root.d.ts +++ b/packages/ember-glimmer/lib/templates/root.d.ts @@ -1,2 +1,3 @@ -declare const TEMPLATE: any; +import { WrappedTemplateFactory } from '../template'; +declare const TEMPLATE: WrappedTemplateFactory; export default TEMPLATE; diff --git a/packages/ember-glimmer/lib/views/outlet.ts b/packages/ember-glimmer/lib/views/outlet.ts index 26f080d8a1d..049b99c2791 100644 --- a/packages/ember-glimmer/lib/views/outlet.ts +++ b/packages/ember-glimmer/lib/views/outlet.ts @@ -1,28 +1,28 @@ import { Simple } from '@glimmer/interfaces'; -import { DirtyableTag, VersionedPathReference } from '@glimmer/reference'; +import { DirtyableTag, Tag, TagWrapper, VersionedPathReference } from '@glimmer/reference'; +import { Opaque, Option } from '@glimmer/util'; import { environment } from 'ember-environment'; import { run } from 'ember-metal'; -import { assign } from 'ember-utils'; -import { OWNER } from 'ember-utils'; -import Environment from '../environment'; +import { assign, OWNER } from 'ember-utils'; import { Renderer } from '../renderer'; +import { Container, OwnedTemplate } from '../template'; -export class OutletStateReference implements VersionedPathReference { - public tag: any; +export class RootOutletStateReference implements VersionedPathReference> { + tag: Tag; constructor(public outletView: OutletView) { this.tag = outletView._tag; } - get(key: string): VersionedPathReference { + get(key: string): VersionedPathReference> { return new ChildOutletStateReference(this, key); } - value(): OutletState { + value(): Option { return this.outletView.outletState; } - getOrphan(name: string): VersionedPathReference { + getOrphan(name: string): VersionedPathReference> { return new OrphanedOutletStateReference(this, name); } @@ -34,17 +34,17 @@ export class OutletStateReference implements VersionedPathReference // So this is a relic of the past that SHOULD go away // in 3.0. Preferably it is deprecated in the release that // follows the Glimmer release. -class OrphanedOutletStateReference extends OutletStateReference { +class OrphanedOutletStateReference extends RootOutletStateReference { public root: any; public name: string; - constructor(root, name) { + constructor(root: RootOutletStateReference, name: string) { super(root.outletView); this.root = root; this.name = name; } - value(): OutletState { + value(): Option { let rootState = this.root.value(); let orphans = rootState.outlets.main.outlets.__ember_orphans__; @@ -66,12 +66,12 @@ class OrphanedOutletStateReference extends OutletStateReference { } } -class ChildOutletStateReference { - public parent: any; +class ChildOutletStateReference implements VersionedPathReference> { + public parent: VersionedPathReference>; public key: string; - public tag: any; + public tag: Tag; - constructor(parent, key) { + constructor(parent: VersionedPathReference>, key: string) { this.parent = parent; this.key = key; this.tag = parent.tag; @@ -82,32 +82,40 @@ class ChildOutletStateReference { } value() { - return this.parent.value()[this.key]; + let parent = this.parent.value(); + return parent && parent[this.key]; } } +export interface RenderState { + owner: Container | undefined; + into: string | undefined; + outlet: string; + name: string; + controller: Opaque; + template: OwnedTemplate | undefined; +} + export interface OutletState { outlets: { - [name: string]: OutletState; - }; - render: { - owner: any | undefined, - into: string, - outlet: string, - name: string, - controller: any | undefined, - ViewClass: Function | undefined, - template: any | undefined, + [name: string]: OutletState | undefined; }; + render: RenderState | undefined; +} + +export interface BootEnvironment { + hasDOM: boolean; + isInteractive: boolean; + options: any; } export default class OutletView { - private _environment: Environment; + private _environment: BootEnvironment; public renderer: Renderer; - public owner: any; - public template: any; - public outletState: OutletState; - public _tag: DirtyableTag; + public owner: Container; + public template: OwnedTemplate; + public outletState: Option; + public _tag: TagWrapper; static extend(injections) { return class extends OutletView { @@ -131,13 +139,13 @@ export default class OutletView { return new OutletView(_environment, renderer, owner, template); } - constructor(_environment, renderer, owner, template) { + constructor(_environment: BootEnvironment, renderer: Renderer, owner: Container, template: OwnedTemplate) { this._environment = _environment; this.renderer = renderer; this.owner = owner; this.template = template; this.outletState = null; - this._tag = new DirtyableTag(); + this._tag = DirtyableTag.create(); } appendTo(selector: string | Simple.Element) { @@ -153,7 +161,7 @@ export default class OutletView { run.schedule('render', this.renderer, 'appendOutletView', this, target); } - rerender() { } + rerender() { /**/ } setOutletState(state: OutletState) { this.outletState = { @@ -166,16 +174,15 @@ export default class OutletView { outlet: 'main', name: '-top-level', controller: undefined, - ViewClass: undefined, template: undefined, }, }; - this._tag.dirty(); + this._tag.inner.dirty(); } toReference() { - return new OutletStateReference(this); + return new RootOutletStateReference(this); } - destroy() { } + destroy() { /**/ } } diff --git a/packages/ember-glimmer/tests/integration/outlet-test.js b/packages/ember-glimmer/tests/integration/outlet-test.js index 0737836ea9a..f7cc482f6a5 100644 --- a/packages/ember-glimmer/tests/integration/outlet-test.js +++ b/packages/ember-glimmer/tests/integration/outlet-test.js @@ -19,7 +19,6 @@ moduleFor('outlet view', class extends RenderingTest { outlet: 'main', name: 'application', controller: undefined, - ViewClass: undefined, template: undefined }, @@ -41,7 +40,6 @@ moduleFor('outlet view', class extends RenderingTest { outlet: 'main', name: 'application', controller: undefined, - ViewClass: undefined, template: undefined }, @@ -62,7 +60,6 @@ moduleFor('outlet view', class extends RenderingTest { outlet: 'main', name: 'application', controller: {}, - ViewClass: undefined, template: this.owner.lookup('template:application') }, outlets: Object.create(null) @@ -82,7 +79,6 @@ moduleFor('outlet view', class extends RenderingTest { outlet: 'main', name: 'index', controller: {}, - ViewClass: undefined, template: this.owner.lookup('template:index') }, outlets: Object.create(null) @@ -102,7 +98,6 @@ moduleFor('outlet view', class extends RenderingTest { outlet: 'main', name: 'application', controller: {}, - ViewClass: undefined, template: this.owner.lookup('template:application') }, outlets: Object.create(null) @@ -124,7 +119,6 @@ moduleFor('outlet view', class extends RenderingTest { outlet: 'main', name: 'index', controller: {}, - ViewClass: undefined, template: this.owner.lookup('template:index') }, outlets: Object.create(null) @@ -144,7 +138,6 @@ moduleFor('outlet view', class extends RenderingTest { outlet: 'main', name: 'application', controller: {}, - ViewClass: undefined, template: this.owner.lookup('template:application') }, outlets: Object.create(null) @@ -166,7 +159,6 @@ moduleFor('outlet view', class extends RenderingTest { outlet: 'main', name: 'special', controller: {}, - ViewClass: undefined, template: this.owner.lookup('template:special') }, outlets: Object.create(null) @@ -186,7 +178,6 @@ moduleFor('outlet view', class extends RenderingTest { outlet: 'main', name: 'application', controller: {}, - ViewClass: undefined, template: this.owner.lookup('template:application') }, outlets: Object.create(null) @@ -208,7 +199,6 @@ moduleFor('outlet view', class extends RenderingTest { outlet: 'main', name: 'special', controller: {}, - ViewClass: undefined, template: this.owner.lookup('template:special') }, outlets: Object.create(null) @@ -229,7 +219,6 @@ moduleFor('outlet view', class extends RenderingTest { outlet: 'main', name: 'application', controller, - ViewClass: undefined, template: this.owner.lookup('template:application') }, outlets: Object.create(null) @@ -251,7 +240,6 @@ moduleFor('outlet view', class extends RenderingTest { outlet: 'main', name: 'foo', controller: {}, - ViewClass: undefined, template: this.owner.lookup('template:foo') }, outlets: Object.create(null) @@ -265,7 +253,6 @@ moduleFor('outlet view', class extends RenderingTest { outlet: 'main', name: 'bar', controller: {}, - ViewClass: undefined, template: this.owner.lookup('template:bar') }, outlets: Object.create(null) @@ -297,7 +284,6 @@ moduleFor('outlet view', class extends RenderingTest { outlet: 'main', name: 'outer', controller: {}, - ViewClass: undefined, template: this.owner.lookup('template:outer') }, outlets: { @@ -308,7 +294,6 @@ moduleFor('outlet view', class extends RenderingTest { outlet: 'main', name: 'inner', controller: {}, - ViewClass: undefined, template: this.owner.lookup('template:inner') }, outlets: Object.create(null) diff --git a/packages/ember-routing/lib/system/route.js b/packages/ember-routing/lib/system/route.js index 8282d64bc1e..3a596aa5ff2 100644 --- a/packages/ember-routing/lib/system/route.js +++ b/packages/ember-routing/lib/system/route.js @@ -2178,7 +2178,6 @@ let Route = EmberObject.extend(ActionHandler, Evented, { name: connection.name, controller: undefined, template: undefined, - ViewClass: undefined }; run.once(this.router, '_setOutlets'); } @@ -2283,7 +2282,6 @@ function buildRenderOptions(route, isDefaultRender, _name, options) { name, controller, template: template || route._topLevelViewTemplate, - ViewClass: undefined }; if (DEBUG) { diff --git a/tests/node/helpers/component-module.js b/tests/node/helpers/component-module.js index 92264d6feec..f197049e5b0 100644 --- a/tests/node/helpers/component-module.js +++ b/tests/node/helpers/component-module.js @@ -74,8 +74,7 @@ function setupComponentTest() { outlet: 'main', name: 'application', controller: module, - ViewClass: undefined, - template: OutletTemplate + template: OutletTemplate, }, outlets: { } @@ -108,7 +107,6 @@ function render(_template) { outlet: 'main', name: 'index', controller: this, - ViewClass: undefined, template: this.owner.lookup(templateFullName), outlets: { } }; diff --git a/tsconfig.json b/tsconfig.json index 28dbdab8069..cdfa2ec8735 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -19,7 +19,7 @@ "noUnusedLocals": true, "noUnusedParameters": true, // "allowUnreachableCode": false, - // "strictNullChecks": true, + "strictNullChecks": true, "noImplicitReturns": true, "noImplicitThis": true, From 145711188a89a8cbdec0edc281d96cd74ba5780f Mon Sep 17 00:00:00 2001 From: Kris Selden Date: Thu, 26 Oct 2017 02:11:10 -0700 Subject: [PATCH 23/24] add more typing --- packages/ember-environment/lib/index.d.ts | 10 ++++++ .../lib/component-managers/curly.ts | 2 +- packages/ember-glimmer/lib/component.ts | 11 +++--- packages/ember-glimmer/lib/utils/string.ts | 12 +++---- packages/ember-glimmer/lib/utils/to-bool.ts | 3 +- packages/ember-glimmer/lib/views/outlet.ts | 20 +++++------ packages/ember-runtime/lib/index.d.ts | 23 ++++++++++++ packages/ember-utils/lib/index.d.ts | 12 +++++++ packages/ember-utils/lib/symbol.js | 2 +- packages/ember-views/lib/index.d.ts | 36 +++++++++++++++++++ 10 files changed, 108 insertions(+), 23 deletions(-) create mode 100644 packages/ember-environment/lib/index.d.ts create mode 100644 packages/ember-runtime/lib/index.d.ts create mode 100644 packages/ember-utils/lib/index.d.ts create mode 100644 packages/ember-views/lib/index.d.ts diff --git a/packages/ember-environment/lib/index.d.ts b/packages/ember-environment/lib/index.d.ts new file mode 100644 index 00000000000..88125afe618 --- /dev/null +++ b/packages/ember-environment/lib/index.d.ts @@ -0,0 +1,10 @@ +export const environment: { + hasDOM: boolean; + isChrome: boolean; + isFirefox: boolean; + isPhantom: boolean; + location: Location | null; + history: History | null; + userAgent: string; + window: Window | null; +}; diff --git a/packages/ember-glimmer/lib/component-managers/curly.ts b/packages/ember-glimmer/lib/component-managers/curly.ts index 7afcbc03530..a9021ac43f8 100644 --- a/packages/ember-glimmer/lib/component-managers/curly.ts +++ b/packages/ember-glimmer/lib/component-managers/curly.ts @@ -3,6 +3,7 @@ import { ComponentDefinition, PrimitiveReference, } from '@glimmer/runtime'; +import { Opaque } from '@glimmer/util'; import { privatize as P } from 'container'; import { assert, @@ -14,7 +15,6 @@ import { } from 'ember-metal'; import { assign, - Opaque, OWNER, } from 'ember-utils'; import { setViewElement } from 'ember-views'; diff --git a/packages/ember-glimmer/lib/component.ts b/packages/ember-glimmer/lib/component.ts index a96364791eb..0a12066d573 100644 --- a/packages/ember-glimmer/lib/component.ts +++ b/packages/ember-glimmer/lib/component.ts @@ -617,11 +617,14 @@ const Component = CoreView.extend( this._super(); }, - __defineNonEnumerable(property) { + __defineNonEnumerable(property: { + name: string; + descriptor: { value: any } + }) { this[property.name] = property.descriptor.value; }, - [PROPERTY_DID_CHANGE](key) { + [PROPERTY_DID_CHANGE](key: string) { if (this[IS_DISPATCHING_ATTRS]) { return; } let args = this[ARGS]; @@ -634,7 +637,7 @@ const Component = CoreView.extend( } }, - getAttr(key) { + getAttr(key: string) { // TODO Intimate API should be deprecated return this.get(key); }, @@ -670,7 +673,7 @@ const Component = CoreView.extend( @return String @public */ - readDOMAttr(name) { + readDOMAttr(name: string) { let element = getViewElement(this); return readDOMAttr(element, name); }, diff --git a/packages/ember-glimmer/lib/utils/string.ts b/packages/ember-glimmer/lib/utils/string.ts index af50fbf9782..796268110a8 100644 --- a/packages/ember-glimmer/lib/utils/string.ts +++ b/packages/ember-glimmer/lib/utils/string.ts @@ -7,7 +7,7 @@ import { deprecate } from 'ember-debug'; export class SafeString { public string: string; - constructor(string) { + constructor(string: string) { this.string = string; } @@ -49,11 +49,11 @@ const escape = { const possible = /[&<>"'`=]/; const badChars = /[&<>"'`=]/g; -function escapeChar(chr) { +function escapeChar(chr: keyof typeof escape) { return escape[chr]; } -export function escapeExpression(string) { +export function escapeExpression(string: string | SafeString) { if (typeof string !== 'string') { // don't escape SafeStrings, since they're already safe if (string && string.toHTML) { @@ -91,7 +91,7 @@ export function escapeExpression(string) { @return {Handlebars.SafeString} A string that will not be HTML escaped by Handlebars. @public */ -export function htmlSafe(str) { +export function htmlSafe(str: string) { if (str === null || str === undefined) { str = ''; } else if (typeof str !== 'string') { @@ -119,6 +119,6 @@ export function htmlSafe(str) { @return {Boolean} `true` if the string was decorated with `htmlSafe`, `false` otherwise. @public */ -export function isHTMLSafe(str) { - return str && typeof str.toHTML === 'function'; +export function isHTMLSafe(str: string | SafeString): str is SafeString { + return str !== null && typeof str === 'object' && typeof str.toHTML === 'function'; } diff --git a/packages/ember-glimmer/lib/utils/to-bool.ts b/packages/ember-glimmer/lib/utils/to-bool.ts index de09e00524b..bc23f817b0a 100644 --- a/packages/ember-glimmer/lib/utils/to-bool.ts +++ b/packages/ember-glimmer/lib/utils/to-bool.ts @@ -1,7 +1,8 @@ +import { Opaque } from '@glimmer/interfaces'; import { get } from 'ember-metal'; import { isArray } from 'ember-runtime'; -export default function toBool(predicate) { +export default function toBool(predicate: Opaque) { if (!predicate) { return false; } diff --git a/packages/ember-glimmer/lib/views/outlet.ts b/packages/ember-glimmer/lib/views/outlet.ts index 049b99c2791..238579daaa5 100644 --- a/packages/ember-glimmer/lib/views/outlet.ts +++ b/packages/ember-glimmer/lib/views/outlet.ts @@ -14,7 +14,7 @@ export class RootOutletStateReference implements VersionedPathReference> { + get(key: string): VersionedPathReference { return new ChildOutletStateReference(this, key); } @@ -66,22 +66,22 @@ class OrphanedOutletStateReference extends RootOutletStateReference { } } -class ChildOutletStateReference implements VersionedPathReference> { - public parent: VersionedPathReference>; +class ChildOutletStateReference implements VersionedPathReference { + public parent: VersionedPathReference; public key: string; public tag: Tag; - constructor(parent: VersionedPathReference>, key: string) { + constructor(parent: VersionedPathReference, key: string) { this.parent = parent; this.key = key; this.tag = parent.tag; } - get(key) { + get(key: string): VersionedPathReference { return new ChildOutletStateReference(this, key); } - value() { + value(): any { let parent = this.parent.value(); return parent && parent[this.key]; } @@ -117,9 +117,9 @@ export default class OutletView { public outletState: Option; public _tag: TagWrapper; - static extend(injections) { + static extend(injections: any) { return class extends OutletView { - static create(options) { + static create(options: any) { if (options) { return super.create(assign({}, injections, options)); } else { @@ -129,11 +129,11 @@ export default class OutletView { }; } - static reopenClass(injections) { + static reopenClass(injections: any) { assign(this, injections); } - static create(options) { + static create(options: any) { let { _environment, renderer, template } = options; let owner = options[OWNER]; return new OutletView(_environment, renderer, owner, template); diff --git a/packages/ember-runtime/lib/index.d.ts b/packages/ember-runtime/lib/index.d.ts new file mode 100644 index 00000000000..2edc0f9536e --- /dev/null +++ b/packages/ember-runtime/lib/index.d.ts @@ -0,0 +1,23 @@ +export const TargetActionSupport: any; +export function isArray(arr: any): boolean; +export const ControllerMixin: any; + +export function deprecatingAlias(name: string, opts: { + id: string; + until: string; +}): any; + +export const inject: { + service(name: string): any; +}; + +export const FrameworkObject: any; + +export const String: { + dasherize(s: string): string; + loc(s: string, ...args: string[]): string; +}; + +export function objectAt(arr: any, i: number): any; + +export function isEmberArray(arr: any): boolean; diff --git a/packages/ember-utils/lib/index.d.ts b/packages/ember-utils/lib/index.d.ts new file mode 100644 index 00000000000..04694a4db12 --- /dev/null +++ b/packages/ember-utils/lib/index.d.ts @@ -0,0 +1,12 @@ +import { Opaque } from '@glimmer/interfaces'; + +export const NAME_KEY: string; +export function getOwner(obj: any): any; +export function symbol(debugName: string): string; +export function assign(original: any, ...args: any[]): any; +export const OWNER: string; +export const HAS_NATIVE_WEAKMAP: boolean; + +export function generateGuid(obj: Opaque, prefix?: string): string; +export function guidFor(obj: Opaque): string; +export function uuid(): number; diff --git a/packages/ember-utils/lib/symbol.js b/packages/ember-utils/lib/symbol.js index eea5e7e7ca4..c380c39bbc0 100644 --- a/packages/ember-utils/lib/symbol.js +++ b/packages/ember-utils/lib/symbol.js @@ -6,5 +6,5 @@ export default function symbol(debugName) { // want to require non-enumerability for this API, which // would introduce a large cost. let id = GUID_KEY + Math.floor(Math.random() * new Date()); - return intern(`__${debugName}__ [id=${id}]`); + return intern(`__${debugName}${id}__`); } diff --git a/packages/ember-views/lib/index.d.ts b/packages/ember-views/lib/index.d.ts new file mode 100644 index 00000000000..c5f3c123e98 --- /dev/null +++ b/packages/ember-views/lib/index.d.ts @@ -0,0 +1,36 @@ +import { Opaque } from '@glimmer/util'; + +export const ActionSupport: any; +export const ChildViewsSupport: any; +export const ClassNamesSupport: any; +export const CoreView: any; +export const ViewMixin: any; +export const ViewStateSupport: any; +export const TextSupport: any; + +export function getViewElement(view: Opaque): Element; +export function setViewElement(view: Opaque, element: Element); + +export function isSimpleClick(event: Event): boolean; + +export function constructStyleDeprecationMessage(affectedStyle: string): string; + +export function hasPartial(name: string, owner: any): boolean; + +export function lookupComponent(owner: any, name: string, options: any): any; + +export function lookupPartial(templateName: string, owner: any): any; + +export function getViewId(view: any): string; + +export const fallbackViewRegistry: { + [id: string]: any | undefined; +} + +export const MUTABLE_CELL: string; + +export const ActionManager: { + registeredActions: { + [id: string]: any | undefined; + } +}; From 29689a3a94a98bb262d775a3a242d07468a278d3 Mon Sep 17 00:00:00 2001 From: Kris Selden Date: Thu, 26 Oct 2017 02:29:58 -0700 Subject: [PATCH 24/24] fix test --- packages/ember-glimmer/lib/environment.ts | 19 ++++++++++++------- packages/ember-views/lib/index.d.ts | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/ember-glimmer/lib/environment.ts b/packages/ember-glimmer/lib/environment.ts index ade59e95ca8..3fd1e9fc12e 100644 --- a/packages/ember-glimmer/lib/environment.ts +++ b/packages/ember-glimmer/lib/environment.ts @@ -104,7 +104,7 @@ export default class Environment extends GlimmerEnvironment { name: string; source: string; owner: Container; - }, CurlyComponentDefinition>; + }, CurlyComponentDefinition | undefined>; private _templateCache: Cache<{ Template: WrappedTemplateFactory | OwnedTemplate; owner: Container; @@ -124,14 +124,17 @@ export default class Environment extends GlimmerEnvironment { this._definitionCache = new Cache(2000, ({ name, source, owner }) => { let { component: componentFactory, layout } = lookupComponent(owner, name, { source }); let customManager: any; - if (GLIMMER_CUSTOM_COMPONENT_MANAGER) { - let managerId = layout && layout.meta.managerId; + if (componentFactory || layout) { + if (GLIMMER_CUSTOM_COMPONENT_MANAGER) { + let managerId = layout && layout.meta.managerId; - if (managerId) { - customManager = owner.factoryFor(`component-manager:${managerId}`).class; + if (managerId) { + customManager = owner.factoryFor(`component-manager:${managerId}`).class; + } } + return new CurlyComponentDefinition(name, componentFactory, layout, undefined, customManager); } - return new CurlyComponentDefinition(name, componentFactory, layout, undefined, customManager); + return undefined; }, ({ name, source, owner }) => { let expandedName = source && this._resolveLocalLookupName(name, source, owner) || name; @@ -216,7 +219,9 @@ export default class Environment extends GlimmerEnvironment { let source = moduleName && `template:${moduleName}`; let definition = this._definitionCache.get({ name, source, owner }); finalizer(); - return definition; + // TODO the glimmer-vm wants this to always have a def + // but internally we need it to sometimes be undefined + return definition!; } // normally templates should be exported at the proper module name diff --git a/packages/ember-views/lib/index.d.ts b/packages/ember-views/lib/index.d.ts index c5f3c123e98..d95530abbd5 100644 --- a/packages/ember-views/lib/index.d.ts +++ b/packages/ember-views/lib/index.d.ts @@ -9,7 +9,7 @@ export const ViewStateSupport: any; export const TextSupport: any; export function getViewElement(view: Opaque): Element; -export function setViewElement(view: Opaque, element: Element); +export function setViewElement(view: Opaque, element: Element | null); export function isSimpleClick(event: Event): boolean;