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

[BUGFIX beta] Revert decorator refactors #17649

Merged
merged 1 commit into from Feb 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintrc.js
Expand Up @@ -2,7 +2,6 @@ const path = require('path');

module.exports = {
root: true,
parser: 'babel-eslint',
extends: [
'eslint:recommended',
'prettier',
Expand Down
10 changes: 1 addition & 9 deletions broccoli/packages.js
Expand Up @@ -16,7 +16,6 @@ const WriteFile = require('broccoli-file-creator');
const StringReplace = require('broccoli-string-replace');
const GlimmerTemplatePrecompiler = require('./glimmer-template-compiler');
const VERSION_PLACEHOLDER = /VERSION_STRING_PLACEHOLDER/g;
const transfromBabelPlugins = require('./transforms/transform-babel-plugins');

const debugTree = BroccoliDebug.buildDebugCallback('ember-source');

Expand Down Expand Up @@ -84,13 +83,6 @@ module.exports.getPackagesES = function getPackagesES() {
exclude: ['**/*.ts'],
});

// tsc / typescript handles decorators and class properties on its own
// so for non ts, transpile the proposal features (decorators, etc)
let transpiledProposals = debugTree(
transfromBabelPlugins(debugTree(nonTypeScriptContents, `get-packages-es:babel-plugins:input`)),
`get-packages-es:babel-plugins:output`
);

let typescriptContents = new Funnel(debuggedCompiledTemplatesAndTypeScript, {
include: ['**/*.ts'],
});
Expand All @@ -103,7 +95,7 @@ module.exports.getPackagesES = function getPackagesES() {

let debuggedCompiledTypescript = debugTree(typescriptCompiled, `get-packages-es:ts:output`);

let mergedFinalOutput = new MergeTrees([transpiledProposals, debuggedCompiledTypescript], {
let mergedFinalOutput = new MergeTrees([nonTypeScriptContents, debuggedCompiledTypescript], {
overwrite: true,
});

Expand Down
13 changes: 0 additions & 13 deletions broccoli/transforms/transform-babel-plugins.js

This file was deleted.

3 changes: 0 additions & 3 deletions package.json
Expand Up @@ -77,8 +77,6 @@
},
"devDependencies": {
"@babel/helper-module-imports": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.3.3",
"@babel/plugin-proposal-decorators": "^7.3.0",
"@babel/plugin-transform-arrow-functions": "^7.2.0",
"@babel/plugin-transform-block-scoping": "^7.2.0",
"@babel/plugin-transform-classes": "^7.3.3",
Expand All @@ -103,7 +101,6 @@
"@types/rsvp": "^4.0.2",
"auto-dist-tag": "^1.0.0",
"aws-sdk": "^2.404.0",
"babel-eslint": "^10.0.1",
"babel-plugin-debug-macros": "^0.3.0",
"babel-plugin-filter-imports": "^2.0.4",
"babel-plugin-module-resolver": "^3.2.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/@ember/-internals/meta/index.ts
@@ -1,6 +1,8 @@
export {
counters,
deleteMeta,
descriptorFor,
isDescriptor,
Meta,
meta,
MetaCounters,
Expand Down
42 changes: 42 additions & 0 deletions packages/@ember/-internals/meta/lib/meta.ts
Expand Up @@ -965,6 +965,48 @@ if (DEBUG) {
meta._counters = counters;
}

/**
Returns the CP descriptor assocaited with `obj` and `keyName`, if any.

@method descriptorFor
@param {Object} obj the object to check
@param {String} keyName the key to check
@return {Descriptor}
@private
*/
export function descriptorFor(obj: object, keyName: string, _meta?: Meta | null) {
assert('Cannot call `descriptorFor` on null', obj !== null);
assert('Cannot call `descriptorFor` on undefined', obj !== undefined);
assert(
`Cannot call \`descriptorFor\` on ${typeof obj}`,
typeof obj === 'object' || typeof obj === 'function'
);

let meta = _meta === undefined ? peekMeta(obj) : _meta;

if (meta !== null) {
return meta.peekDescriptors(keyName);
}
}

/**
Check whether a value is a CP descriptor.

@method isDescriptor
@param {any} possibleDesc the value to check
@return {boolean}
@private
*/
export function isDescriptor(possibleDesc: any | undefined | null): boolean {
// TODO make this return `possibleDesc is Descriptor`
return (
possibleDesc !== undefined &&
possibleDesc !== null &&
typeof possibleDesc === 'object' &&
possibleDesc.isDescriptor === true
);
}

export { counters };

function indexOfListener(
Expand Down
15 changes: 5 additions & 10 deletions packages/@ember/-internals/metal/index.ts
@@ -1,4 +1,4 @@
export { default as computed, _globalsComputed, ComputedProperty } from './lib/computed';
export { default as computed, ComputedProperty, _globalsComputed } from './lib/computed';
export { getCacheFor, getCachedValueFor, peekCacheFor } from './lib/computed_cache';
export { default as alias } from './lib/alias';
export { deprecateProperty } from './lib/deprecate_property';
Expand Down Expand Up @@ -28,13 +28,7 @@ export {
overrideChains,
PROPERTY_DID_CHANGE,
} from './lib/property_events';
export { defineProperty } from './lib/properties';
export { nativeDescDecorator } from './lib/decorator';
export {
descriptorForProperty,
isComputedDecorator,
setComputedDecorator,
} from './lib/descriptor_map';
export { defineProperty, Descriptor } from './lib/properties';
export { watchKey, unwatchKey } from './lib/watch_key';
export { ChainNode, finishChains, removeChainWatcher } from './lib/chains';
export { watchPath, unwatchPath } from './lib/watch_path';
Expand All @@ -46,10 +40,11 @@ export { default as expandProperties } from './lib/expand_properties';

export { addObserver, removeObserver } from './lib/observer';
export { Mixin, aliasMethod, mixin, observer, applyMixin } from './lib/mixin';
export { default as inject, DEBUG_INJECTION_FUNCTIONS } from './lib/injected_property';
export { default as InjectedProperty } from './lib/injected_property';
export { setHasViews, tagForProperty, tagFor, markObjectAsDirty } from './lib/tags';
export { default as runInTransaction, didRender, assertNotRendered } from './lib/transaction';
export { tracked, getCurrentTracker, setCurrentTracker } from './lib/tracked';
export { default as descriptor } from './lib/descriptor';
export { tracked } from './lib/tracked';

export {
NAMESPACES,
Expand Down
57 changes: 18 additions & 39 deletions packages/@ember/-internals/metal/lib/alias.ts
Expand Up @@ -2,51 +2,25 @@ import { Meta, meta as metaFor } from '@ember/-internals/meta';
import { inspect } from '@ember/-internals/utils';
import { assert } from '@ember/debug';
import EmberError from '@ember/error';
import { ComputedProperty } from './computed';
import { getCachedValueFor, getCacheFor } from './computed_cache';
import {
addDependentKeys,
ComputedDescriptor,
Decorator,
makeComputedDecorator,
DescriptorWithDependentKeys,
removeDependentKeys,
} from './decorator';
import { descriptorForDecorator } from './descriptor_map';
import { defineProperty } from './properties';
} from './dependent_keys';
import { defineProperty, Descriptor } from './properties';
import { get } from './property_get';
import { set } from './property_set';

const CONSUMED = Object.freeze({});

export type AliasDecorator = Decorator & PropertyDecorator & AliasDecoratorImpl;

export default function alias(altKey: string): AliasDecorator {
return makeComputedDecorator(new AliasedProperty(altKey), AliasDecoratorImpl) as AliasDecorator;
}

// TODO: This class can be svelted once `meta` has been deprecated
class AliasDecoratorImpl extends Function {
readOnly(this: Decorator) {
(descriptorForDecorator(this) as AliasedProperty).readOnly();
return this;
}

oneWay(this: Decorator) {
(descriptorForDecorator(this) as AliasedProperty).oneWay();
return this;
}

meta(this: Decorator, meta?: any): any {
let prop = descriptorForDecorator(this) as AliasedProperty;

if (arguments.length === 0) {
return prop._meta || {};
} else {
prop._meta = meta;
}
}
export default function alias(altKey: string): AliasedProperty {
return new AliasedProperty(altKey);
}

export class AliasedProperty extends ComputedDescriptor {
export class AliasedProperty extends Descriptor implements DescriptorWithDependentKeys {
readonly _dependentKeys: string[];
readonly altKey: string;

constructor(altKey: string) {
Expand All @@ -55,10 +29,9 @@ export class AliasedProperty extends ComputedDescriptor {
this._dependentKeys = [altKey];
}

setup(obj: object, keyName: string, propertyDesc: PropertyDescriptor, meta: Meta): void {
setup(obj: object, keyName: string, meta: Meta): void {
assert(`Setting alias '${keyName}' on self`, this.altKey !== keyName);
super.setup(obj, keyName, propertyDesc, meta);

super.setup(obj, keyName, meta);
if (meta.peekWatching(keyName) > 0) {
this.consume(obj, keyName, meta);
}
Expand Down Expand Up @@ -101,12 +74,14 @@ export class AliasedProperty extends ComputedDescriptor {
return set(obj, this.altKey, value);
}

readOnly(): void {
readOnly(): this {
this.set = AliasedProperty_readOnlySet;
return this;
}

oneWay(): void {
oneWay(): this {
this.set = AliasedProperty_oneWaySet;
return this;
}
}

Expand All @@ -119,3 +94,7 @@ function AliasedProperty_oneWaySet(obj: object, keyName: string, value: any): an
defineProperty(obj, keyName, null);
return set(obj, keyName, value);
}

// Backwards compatibility with Ember Data.
(AliasedProperty.prototype as any)._meta = undefined;
(AliasedProperty.prototype as any).meta = ComputedProperty.prototype.meta;
5 changes: 2 additions & 3 deletions packages/@ember/-internals/metal/lib/chains.ts
@@ -1,6 +1,5 @@
import { Meta, meta as metaFor, peekMeta } from '@ember/-internals/meta';
import { descriptorFor, Meta, meta as metaFor, peekMeta } from '@ember/-internals/meta';
import { getCachedValueFor } from './computed_cache';
import { descriptorForProperty } from './descriptor_map';
import { eachProxyFor } from './each_proxy';
import { get } from './property_get';
import { unwatchKey, watchKey } from './watch_key';
Expand All @@ -10,7 +9,7 @@ function isObject(obj: any): obj is object {
}

function isVolatile(obj: any, keyName: string, meta?: Meta | null): boolean {
let desc = descriptorForProperty(obj, keyName, meta);
let desc = descriptorFor(obj, keyName, meta);
return !(desc !== undefined && desc._volatile === false);
}

Expand Down