Skip to content

Commit

Permalink
Migrate Ember.String to @ember/string.
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue committed Apr 17, 2018
1 parent 61475c5 commit 8499693
Show file tree
Hide file tree
Showing 29 changed files with 200 additions and 231 deletions.
3 changes: 2 additions & 1 deletion packages/@ember/application/globals-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import { dictionary } from 'ember-utils';
import { get, findNamespace } from 'ember-metal';
import { assert, info } from 'ember-debug';
import { capitalize, classify, decamelize, dasherize, Object as EmberObject } from 'ember-runtime';
import { capitalize, classify, dasherize, decamelize } from '@ember/string';
import { Object as EmberObject } from 'ember-runtime';
import validateType from './lib/validate-type';
import { getTemplate } from 'ember-glimmer';
import { DEBUG } from '@glimmer/env';
Expand Down
2 changes: 2 additions & 0 deletions packages/@ember/string/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export function dasherize(s: string): string;
export function loc(s: string, ...args: string[]): string;
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
/**
@module @ember/string
*/

export { getStrings as _getStrings, setStrings as _setStrings } from './lib/string_registry';

import { ENV } from 'ember-environment';
import { Cache } from 'ember-metal';
import { inspect } from 'ember-utils';
import { isArray } from '../utils';
import { get as getString } from '../string_registry';
import { isArray } from 'ember-runtime';
import { getString } from './lib/string_registry';

const STRING_DASHERIZE_REGEXP = /[ _]/g;

Expand Down Expand Up @@ -272,3 +276,142 @@ export function underscore(str) {
export function capitalize(str) {
return CAPITALIZE_CACHE.get(str);
}

const StringPrototype = String.prototype;
if (ENV.EXTEND_PROTOTYPES.String) {
/**
See [String.w](/api/ember/release/classes/String/methods/w?anchor=w).
@method w
@for @ember/string
@static
@private
*/
Object.defineProperty(StringPrototype, 'w', {
configurable: true,
enumerable: false,
writeable: true,
value: function() {
return w(this);
},
});

/**
See [String.loc](/api/ember/release/classes/String/methods/loc?anchor=loc).
@method loc
@for @ember/string
@static
@private
*/
Object.defineProperty(StringPrototype, 'loc', {
configurable: true,
enumerable: false,
writeable: true,
value: function(...args) {
return loc(this, args);
},
});

/**
See [String.camelize](/api/ember/release/classes/String/methods/camelize?anchor=camelize).
@method camelize
@for @ember/string
@static
@private
*/
Object.defineProperty(StringPrototype, 'camelize', {
configurable: true,
enumerable: false,
writeable: true,
value: function() {
return camelize(this);
},
});

/**
See [String.decamelize](/api/ember/release/classes/String/methods/decamelize?anchor=decamelize).
@method decamelize
@for @ember/string
@static
@private
*/
Object.defineProperty(StringPrototype, 'decamelize', {
configurable: true,
enumerable: false,
writeable: true,
value: function() {
return decamelize(this);
},
});

/**
See [String.dasherize](/api/ember/release/classes/String/methods/dasherize?anchor=dasherize).
@method dasherize
@for @ember/string
@static
@private
*/
Object.defineProperty(StringPrototype, 'dasherize', {
configurable: true,
enumerable: false,
writeable: true,
value: function() {
return dasherize(this);
},
});

/**
See [String.underscore](/api/ember/release/classes/String/methods/underscore?anchor=underscore).
@method underscore
@for @ember/string
@static
@private
*/
Object.defineProperty(StringPrototype, 'underscore', {
configurable: true,
enumerable: false,
writeable: true,
value: function() {
return underscore(this);
},
});

/**
See [String.classify](/api/ember/release/classes/String/methods/classify?anchor=classify).
@method classify
@for @ember/string
@static
@private
*/
Object.defineProperty(StringPrototype, 'classify', {
configurable: true,
enumerable: false,
writeable: true,
value: function() {
return classify(this);
},
});

/**
See [String.capitalize](/api/ember/release/classes/String/methods/capitalize?anchor=capitalize).
@method capitalize
@for @ember/string
@static
@private
*/
Object.defineProperty(StringPrototype, 'capitalize', {
configurable: true,
enumerable: false,
writeable: true,
value: function() {
return capitalize(this);
},
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export function getStrings() {
return STRINGS;
}

export function get(name) {
export function getString(name) {
return STRINGS[name];
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ENV } from 'ember-environment';
import { camelize } from '../../../lib/system/string';
import { camelize } from '@ember/string';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';

function test(assert, given, expected, description) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ENV } from 'ember-environment';
import { capitalize } from '../../../lib/system/string';
import { capitalize } from '@ember/string';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';

function test(assert, given, expected, description) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ENV } from 'ember-environment';
import { classify } from '../../../lib/system/string';
import { classify } from '@ember/string';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';

function test(assert, given, expected, description) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ENV } from 'ember-environment';
import { dasherize } from '../../../lib/system/string';
import { dasherize } from '@ember/string';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';

function test(assert, given, expected, description) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ENV } from 'ember-environment';
import { decamelize } from '../../../lib/system/string';
import { decamelize } from '@ember/string';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';

function test(assert, given, expected, description) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ENV } from 'ember-environment';
import { loc } from '../../../lib/system/string';
import { setStrings, getStrings } from '../../../lib/string_registry';
import { loc } from '@ember/string';
import { setStrings, getStrings } from '@ember/string/lib/string_registry';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';

let oldString;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ENV } from 'ember-environment';
import { underscore } from '../../../lib/system/string';
import { underscore } from '@ember/string';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';

function test(assert, given, expected, description) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ENV } from 'ember-environment';
import { w } from '../../../lib/system/string';
import { w } from '@ember/string';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';

function test(assert, given, expected, description) {
Expand Down
10 changes: 2 additions & 8 deletions packages/ember-extension-support/lib/container_debug_adapter.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import {
A as emberA,
typeOf,
classify,
dasherize,
Namespace,
Object as EmberObject,
} from 'ember-runtime';
import { classify, dasherize } from '@ember/string';
import { A as emberA, typeOf, Namespace, Object as EmberObject } from 'ember-runtime';

/**
@module @ember/debug
Expand Down
8 changes: 2 additions & 6 deletions packages/ember-extension-support/lib/data_adapter.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { getOwner } from 'ember-owner';
import { scheduleOnce } from '@ember/runloop';
import { get, objectAt, addArrayObserver, removeArrayObserver } from 'ember-metal';
import {
dasherize,
Namespace,
Object as EmberObject,
A as emberA,
} from 'ember-runtime';
import { dasherize } from '@ember/string';
import { Namespace, Object as EmberObject, A as emberA } from 'ember-runtime';

/**
@module @ember/debug
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-glimmer/lib/component-managers/curly.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { _instrumentStart } from '@ember/instrumentation';
import { dasherize } from '@ember/string';
import { DEBUG } from '@glimmer/env';
import {
ComponentCapabilities,
Expand Down Expand Up @@ -27,7 +28,6 @@ import { assert, deprecate } from 'ember-debug';
import { ENV } from 'ember-environment';
import { get } from 'ember-metal';
import { getOwner } from 'ember-owner';
import { dasherize } from 'ember-runtime';
import { assign, guidFor } from 'ember-utils';
import { addChildView, OwnedTemplateMeta, setViewElement } from 'ember-views';
import { BOUNDS, DIRTY_TAG, HAS_BLOCK, IS_DISPATCHING_ATTRS, ROOT_REF } from '../component';
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-glimmer/lib/helpers/-class.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { dasherize } from '@ember/string';
import { Arguments, VM } from '@glimmer/runtime';
import { dasherize } from 'ember-runtime';
import { InternalHelperReference } from '../utils/references';

function classHelper({ positional }: any) {
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-glimmer/lib/helpers/-normalize-class.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { dasherize } from '@ember/string';
import { Arguments, VM } from '@glimmer/runtime';
import { dasherize } from 'ember-runtime';
import { InternalHelperReference } from '../utils/references';

function normalizeClass({ positional }: any) {
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-glimmer/lib/helpers/loc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@module ember
*/

import { loc } from 'ember-runtime';
import { loc } from '@ember/string';
import { helper } from '../helper';

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-glimmer/lib/utils/bindings.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { dasherize } from '@ember/string';
import { Opaque, Option, Simple } from '@glimmer/interfaces';
import { CachedReference, combine, map, Reference, Tag } from '@glimmer/reference';
import { ElementOperations, PrimitiveReference } from '@glimmer/runtime';
import { Core, Ops } from '@glimmer/wire-format';
import { assert } from 'ember-debug';
import { get } from 'ember-metal';
import { dasherize } from 'ember-runtime';
import { ROOT_REF } from '../component';
import { Component } from './curly-component-state-bucket';
import { referenceFromParts } from './references';
Expand Down
6 changes: 3 additions & 3 deletions packages/ember-glimmer/tests/integration/helpers/loc-test.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { RenderingTest, moduleFor } from '../../utils/test-case';
import { set } from 'ember-metal';
import { setStrings } from 'ember-runtime';
import { _setStrings } from '@ember/string';

moduleFor(
'Helpers test: {{loc}}',
class extends RenderingTest {
constructor() {
super(...arguments);
setStrings({
_setStrings({
'Hello Friend': 'Hallo Freund',
Hello: 'Hallo, %@',
});
}

teardown() {
super.teardown();
setStrings({});
_setStrings({});
}

['@test it lets the original value through by default']() {
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-routing/lib/system/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { once } from '@ember/runloop';
import { get, set, getProperties, setProperties, computed, isEmpty } from 'ember-metal';
import { assert, info, isTesting, deprecate } from 'ember-debug';
import { DEBUG } from '@glimmer/env';
import { classify } from '@ember/string';
import {
typeOf,
copy,
classify,
Object as EmberObject,
A as emberA,
Evented,
Expand Down
3 changes: 0 additions & 3 deletions packages/ember-runtime/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ export const inject: {

export const FrameworkObject: any;

export function dasherize(s: string): string;
export function loc(s: string, ...args: string[]): string;

export function isEmberArray(arr: any): boolean;

export function _contentFor(proxy: any): any;
12 changes: 0 additions & 12 deletions packages/ember-runtime/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
export { default as Object, FrameworkObject } from './lib/system/object';
export {
loc,
w,
dasherize,
decamelize,
camelize,
classify,
underscore,
capitalize,
} from './lib/system/string';
export { default as RegistryProxyMixin } from './lib/mixins/registry_proxy';
export { default as ContainerProxyMixin } from './lib/mixins/container_proxy';
export { default as copy } from './lib/copy';
Expand Down Expand Up @@ -77,7 +67,5 @@ export {
export { default as Service } from './lib/system/service';
export { default as RSVP, onerrorDefault } from './lib/ext/rsvp'; // just for side effect of extending Ember.RSVP
export { isArray, typeOf } from './lib/utils';
export { getStrings, setStrings } from './lib/string_registry';

import './lib/ext/string'; // just for side effect of extending String.prototype
import './lib/ext/function'; // just for side effect of extending Function.prototype
Loading

0 comments on commit 8499693

Please sign in to comment.