Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Typed ember glimmer #15759

Merged
merged 24 commits into from
Oct 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ publish_to_bower/
bower_components/
npm-debug.log
.ember-cli
DEBUG/
11 changes: 4 additions & 7 deletions bin/yarn-link-glimmer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion broccoli/glimmer-template-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ GlimmerTemplatePrecompiler.prototype.processString = function(content, relativeP
`;
};

module.exports = GlimmerTemplatePrecompiler;
module.exports = GlimmerTemplatePrecompiler;
27 changes: 22 additions & 5 deletions broccoli/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ 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 BroccoliDebug = require('broccoli-debug');
const findLib = require('./find-lib');
const funnelLib = require('./funnel-lib');
const { VERSION } = require('./version');
Expand All @@ -15,6 +17,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: {
Expand Down Expand Up @@ -57,16 +61,29 @@ 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/lib', {
destDir: 'packages/ember-glimmer/lib'
});

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 = filterTypeScript(debuggedCompiledTemplatesAndTypeScript);

let funneled = new Funnel(typescriptCompiled, {
getDestinationPath(path) {
return path.replace('/lib/', '/').replace('packages/', '/');
}
});

return debugTree(funneled, 'ember-glimmer:output');
}

module.exports.handlebarsES = function _handlebars() {
Expand Down Expand Up @@ -174,7 +191,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`
});
Expand Down
20 changes: 15 additions & 5 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -67,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' });
Expand All @@ -89,8 +98,10 @@ module.exports = function(options) {
let backburner = toES5(backburnerES());

// Linting
let emberTestsLinted = emberTests.map(lint);
let emberLinted = emberCoreES6.map(lint);
let packages = new UnwatchedDir('packages');
let linting = lint(new Funnel(packages, {
include: ['**/*.js']
}));

// ES5
let dependenciesES5 = dependenciesES6().map(toES5);
Expand All @@ -101,8 +112,7 @@ module.exports = function(options) {
// Bundling
let emberTestsBundle = new MergeTrees([
...emberTestsES5,
...emberTestsLinted,
...emberLinted,
linting,
loader,
nodeModule,
license,
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -85,10 +86,13 @@
"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",
"broccoli-uglify-sourcemap": "^1.5.2",
"chalk": "^1.1.1",
Expand Down
19 changes: 0 additions & 19 deletions packages/container/tsconfig.json

This file was deleted.

5 changes: 5 additions & 0 deletions packages/ember-debug/lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function assert(message: string, test?: boolean): void;

export function warn(message: string, test: boolean, options?: any): void;

export function deprecate(message: string, test: boolean, options?: any): void;
10 changes: 10 additions & 0 deletions packages/ember-environment/lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -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;
};
12 changes: 12 additions & 0 deletions packages/ember-glimmer/externs.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +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;
}
68 changes: 0 additions & 68 deletions packages/ember-glimmer/lib/component-managers/abstract.js

This file was deleted.

100 changes: 100 additions & 0 deletions packages/ember-glimmer/lib/component-managers/abstract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { ProgramSymbolTable } from '@glimmer/interfaces';
import { Tag, VersionedPathReference } from '@glimmer/reference';
import {
Bounds,
CompiledDynamicTemplate,
ComponentDefinition,
ComponentManager,
DynamicScope,
ElementOperations,
Environment,
PreparedArguments,
} from '@glimmer/runtime';
import { IArguments } from '@glimmer/runtime/dist/types/lib/vm/arguments';
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<T> implements ComponentManager<T> {
public debugStack: typeof DebugStack;
public _pushToDebugStack: (name: string, environment: any) => void;
public _pushEngineToDebugStack: (name: string, environment: any) => void;

constructor() {
this.debugStack = undefined;
}

prepareArgs(_definition: ComponentDefinition<T>, _args: IArguments): Option<PreparedArguments> {
return null;
}

// must be implemented by inheritors, inheritors should also
// call `this._pushToDebugStack` to ensure the rerendering
// assertion messages are properly maintained

abstract create(
env: Environment,
definition: ComponentDefinition<T>,
args: IArguments,
dynamicScope: DynamicScope,
caller: VersionedPathReference<void | {}>,
hasDefaultBlock: boolean): T;
abstract layoutFor(
definition: ComponentDefinition<T>,
component: T,
env: Environment): CompiledDynamicTemplate<ProgramSymbolTable>;
abstract getSelf(component: T): VersionedPathReference<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 {
// noop
}

didCreate(_bucket: T): void {
// noop
}

getTag(_bucket: T): Option<Tag> { return null; }

// inheritors should also call `this._pushToDebugStack`
// to ensure the rerendering assertion messages are
// properly maintained
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 {
// noop
}

didUpdate(_bucket: T): void {
// noop
}

abstract getDestructor(bucket: T): Option<Destroyable>;
}

if (DEBUG) {
AbstractManager.prototype._pushToDebugStack = function(name: string, environment) {
this.debugStack = environment.debugStack;
this.debugStack.push(name);
};

AbstractManager.prototype._pushEngineToDebugStack = function(name: string, environment) {
this.debugStack = environment.debugStack;
this.debugStack.pushEngine(name);
};
}
Loading