From 8a53d0ab43daab39a3cebd4c3be7ae61f0ea8b01 Mon Sep 17 00:00:00 2001 From: Qian Wan Date: Mon, 29 Aug 2022 10:37:10 -0400 Subject: [PATCH 1/8] re-export uniqid --- packages/@ember/helper/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/@ember/helper/index.ts b/packages/@ember/helper/index.ts index 47f98763171..d3f7fedbfb8 100644 --- a/packages/@ember/helper/index.ts +++ b/packages/@ember/helper/index.ts @@ -314,3 +314,4 @@ export { setHelperManager, helperCapabilities as capabilities } from '@glimmer/manager'; export { invokeHelper, hash, array, concat, get, fn } from '@glimmer/runtime'; +export { default as uniqId} from "../-internals/glimmer/lib/helpers/unique-id"; \ No newline at end of file From 861ae8997dc325d91b7581aca52f01e00eef188d Mon Sep 17 00:00:00 2001 From: Qian Wan Date: Mon, 29 Aug 2022 20:23:15 -0400 Subject: [PATCH 2/8] Adding test and also re-organizing the export --- packages/@ember/-internals/glimmer/index.ts | 1 + .../glimmer/lib/helpers/unique-id.ts | 2 +- .../integration/helpers/unique-id-test.js | 28 ++++++++++++++++++- packages/@ember/helper/index.ts | 2 +- packages/ember/tests/reexports_test.js | 1 + 5 files changed, 31 insertions(+), 3 deletions(-) diff --git a/packages/@ember/-internals/glimmer/index.ts b/packages/@ember/-internals/glimmer/index.ts index 825c26f6dbf..3c688b7e716 100644 --- a/packages/@ember/-internals/glimmer/index.ts +++ b/packages/@ember/-internals/glimmer/index.ts @@ -324,3 +324,4 @@ export { setComponentManager, } from './lib/utils/managers'; export { isSerializationFirstNode } from './lib/utils/serialization-first-node-helpers'; +export { uniqueId } from './lib/helpers/unique-id'; diff --git a/packages/@ember/-internals/glimmer/lib/helpers/unique-id.ts b/packages/@ember/-internals/glimmer/lib/helpers/unique-id.ts index 6320c24a3db..93d6f339005 100644 --- a/packages/@ember/-internals/glimmer/lib/helpers/unique-id.ts +++ b/packages/@ember/-internals/glimmer/lib/helpers/unique-id.ts @@ -41,7 +41,7 @@ export default internalHelper((): Reference => { // implementation details into an intimate API. It also ensures that the UUID // always starts with a letter, to avoid creating invalid IDs with a numeric // digit at the start. -function uniqueId() { +export function uniqueId() { // @ts-expect-error this one-liner abuses weird JavaScript semantics that // TypeScript (legitimately) doesn't like, but they're nonetheless valid and // specced. diff --git a/packages/@ember/-internals/glimmer/tests/integration/helpers/unique-id-test.js b/packages/@ember/-internals/glimmer/tests/integration/helpers/unique-id-test.js index 65fe72f9347..3e3cb348618 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/helpers/unique-id-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/helpers/unique-id-test.js @@ -1,8 +1,34 @@ -import { RenderingTestCase, strip, moduleFor, runTask } from 'internal-test-helpers'; +import { + AbstractTestCase, + RenderingTestCase, + strip, + moduleFor, + runTask, +} from 'internal-test-helpers'; import { setProperties } from '@ember/object'; +import { uniqueId } from '@ember/helper'; import { EMBER_UNIQUE_ID_HELPER } from '@ember/canary-features'; if (EMBER_UNIQUE_ID_HELPER) { + moduleFor( + 'Helpers test: {{unique-id}} JS', + class JSRenderingTest extends AbstractTestCase { + constructor(assert) { + super(assert); + this.assert = assert; + } + ['@test it can be invoked as a JS function']() { + let first = uniqueId(); + let second = uniqueId(); + + this.assert.notStrictEqual( + first, + second, + `different invocations of {{unique-id}} should produce different values` + ); + } + } + ); moduleFor( 'Helpers test: {{unique-id}}', class extends RenderingTestCase { diff --git a/packages/@ember/helper/index.ts b/packages/@ember/helper/index.ts index d3f7fedbfb8..0c1095f5d5e 100644 --- a/packages/@ember/helper/index.ts +++ b/packages/@ember/helper/index.ts @@ -314,4 +314,4 @@ export { setHelperManager, helperCapabilities as capabilities } from '@glimmer/manager'; export { invokeHelper, hash, array, concat, get, fn } from '@glimmer/runtime'; -export { default as uniqId} from "../-internals/glimmer/lib/helpers/unique-id"; \ No newline at end of file +export { uniqueId } from "@ember/-internals/glimmer"; \ No newline at end of file diff --git a/packages/ember/tests/reexports_test.js b/packages/ember/tests/reexports_test.js index e60b94bca7e..376370e8604 100644 --- a/packages/ember/tests/reexports_test.js +++ b/packages/ember/tests/reexports_test.js @@ -169,6 +169,7 @@ let allExports = [ ['_hash', '@ember/helper', 'hash'], ['_get', '@ember/helper', 'get'], ['_concat', '@ember/helper', 'concat'], + ['_uniqueId', '@ember/helper', 'uniqueId'], // @ember/object ['Object', '@ember/object', 'default'], From a7e4feac920411a81cc0360a61b6fbdfff695023 Mon Sep 17 00:00:00 2001 From: Qian Wan Date: Mon, 29 Aug 2022 20:28:15 -0400 Subject: [PATCH 3/8] Correcting to single quotes --- packages/@ember/helper/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@ember/helper/index.ts b/packages/@ember/helper/index.ts index 0c1095f5d5e..e3a0e1c4323 100644 --- a/packages/@ember/helper/index.ts +++ b/packages/@ember/helper/index.ts @@ -314,4 +314,4 @@ export { setHelperManager, helperCapabilities as capabilities } from '@glimmer/manager'; export { invokeHelper, hash, array, concat, get, fn } from '@glimmer/runtime'; -export { uniqueId } from "@ember/-internals/glimmer"; \ No newline at end of file +export { uniqueId } from '@ember/-internals/glimmer'; \ No newline at end of file From d864d4be6dbdc6d359aaa34241be40e1616f8c2f Mon Sep 17 00:00:00 2001 From: Qian Wan Date: Mon, 29 Aug 2022 20:31:48 -0400 Subject: [PATCH 4/8] correct test description --- .../glimmer/tests/integration/helpers/unique-id-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@ember/-internals/glimmer/tests/integration/helpers/unique-id-test.js b/packages/@ember/-internals/glimmer/tests/integration/helpers/unique-id-test.js index 3e3cb348618..c1c44f1940c 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/helpers/unique-id-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/helpers/unique-id-test.js @@ -24,7 +24,7 @@ if (EMBER_UNIQUE_ID_HELPER) { this.assert.notStrictEqual( first, second, - `different invocations of {{unique-id}} should produce different values` + `different invocations of uniqueId should produce different values` ); } } From 541b3d9130f6f88c24aad0df2ddfc00af73ca02f Mon Sep 17 00:00:00 2001 From: Qian Wan Date: Tue, 30 Aug 2022 10:12:59 -0400 Subject: [PATCH 5/8] adding empty line to adhere to linting --- packages/@ember/helper/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/@ember/helper/index.ts b/packages/@ember/helper/index.ts index e3a0e1c4323..6fbcfeb94a5 100644 --- a/packages/@ember/helper/index.ts +++ b/packages/@ember/helper/index.ts @@ -314,4 +314,5 @@ export { setHelperManager, helperCapabilities as capabilities } from '@glimmer/manager'; export { invokeHelper, hash, array, concat, get, fn } from '@glimmer/runtime'; + export { uniqueId } from '@ember/-internals/glimmer'; \ No newline at end of file From ffbbe6c6b3c3540926bfabe977dff22be4d4da32 Mon Sep 17 00:00:00 2001 From: Qian Wan Date: Wed, 31 Aug 2022 23:12:55 -0400 Subject: [PATCH 6/8] address lint --- packages/@ember/helper/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@ember/helper/index.ts b/packages/@ember/helper/index.ts index 6fbcfeb94a5..9b81b823bc7 100644 --- a/packages/@ember/helper/index.ts +++ b/packages/@ember/helper/index.ts @@ -315,4 +315,4 @@ export { setHelperManager, helperCapabilities as capabilities } from '@glimmer/manager'; export { invokeHelper, hash, array, concat, get, fn } from '@glimmer/runtime'; -export { uniqueId } from '@ember/-internals/glimmer'; \ No newline at end of file +export { uniqueId } from '@ember/-internals/glimmer'; From 9a5412290b1cc8f62b489dbff7caf79762aaa2ca Mon Sep 17 00:00:00 2001 From: Qian Wan Date: Wed, 31 Aug 2022 23:20:23 -0400 Subject: [PATCH 7/8] place on global --- packages/ember/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/ember/index.js b/packages/ember/index.js index 76febd1bef6..cb3191e9964 100644 --- a/packages/ember/index.js +++ b/packages/ember/index.js @@ -3,6 +3,7 @@ import require, { has } from 'require'; import { getENV, getLookup, setLookup } from '@ember/-internals/environment'; import * as utils from '@ember/-internals/utils'; import { Registry, Container } from '@ember/-internals/container'; +import { uniqueId } from '@ember/-internals/glimmer'; import * as instrumentation from '@ember/instrumentation'; import { meta } from '@ember/-internals/meta'; import * as metal from '@ember/-internals/metal'; @@ -427,6 +428,7 @@ Ember._concat = concat; Ember._get = get; Ember._on = on; Ember._fn = fn; +Ember._uniqueId = uniqueId; Ember._helperManagerCapabilities = helperCapabilities; Ember._setHelperManager = setHelperManager; From b0aadba819a364c8f16b9b325c04e11ee5faec02 Mon Sep 17 00:00:00 2001 From: Qian Wan Date: Fri, 2 Sep 2022 17:22:39 -0400 Subject: [PATCH 8/8] addressed comments to use invokeHelper --- packages/@ember/-internals/glimmer/index.ts | 2 +- .../@ember/-internals/glimmer/lib/helpers/unique-id.ts | 2 +- .../glimmer/tests/integration/helpers/unique-id-test.js | 7 ++++--- packages/ember/index.js | 2 -- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/@ember/-internals/glimmer/index.ts b/packages/@ember/-internals/glimmer/index.ts index 3c688b7e716..b64a7944168 100644 --- a/packages/@ember/-internals/glimmer/index.ts +++ b/packages/@ember/-internals/glimmer/index.ts @@ -324,4 +324,4 @@ export { setComponentManager, } from './lib/utils/managers'; export { isSerializationFirstNode } from './lib/utils/serialization-first-node-helpers'; -export { uniqueId } from './lib/helpers/unique-id'; +export { default as uniqueId } from './lib/helpers/unique-id'; diff --git a/packages/@ember/-internals/glimmer/lib/helpers/unique-id.ts b/packages/@ember/-internals/glimmer/lib/helpers/unique-id.ts index 93d6f339005..6320c24a3db 100644 --- a/packages/@ember/-internals/glimmer/lib/helpers/unique-id.ts +++ b/packages/@ember/-internals/glimmer/lib/helpers/unique-id.ts @@ -41,7 +41,7 @@ export default internalHelper((): Reference => { // implementation details into an intimate API. It also ensures that the UUID // always starts with a letter, to avoid creating invalid IDs with a numeric // digit at the start. -export function uniqueId() { +function uniqueId() { // @ts-expect-error this one-liner abuses weird JavaScript semantics that // TypeScript (legitimately) doesn't like, but they're nonetheless valid and // specced. diff --git a/packages/@ember/-internals/glimmer/tests/integration/helpers/unique-id-test.js b/packages/@ember/-internals/glimmer/tests/integration/helpers/unique-id-test.js index c1c44f1940c..e1261948040 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/helpers/unique-id-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/helpers/unique-id-test.js @@ -6,8 +6,9 @@ import { runTask, } from 'internal-test-helpers'; import { setProperties } from '@ember/object'; -import { uniqueId } from '@ember/helper'; +import { uniqueId, invokeHelper } from '@ember/helper'; import { EMBER_UNIQUE_ID_HELPER } from '@ember/canary-features'; +import { getValue } from '@glimmer/validator'; if (EMBER_UNIQUE_ID_HELPER) { moduleFor( @@ -18,8 +19,8 @@ if (EMBER_UNIQUE_ID_HELPER) { this.assert = assert; } ['@test it can be invoked as a JS function']() { - let first = uniqueId(); - let second = uniqueId(); + let first = getValue(invokeHelper({}, uniqueId())); + let second = getValue(invokeHelper({}, uniqueId())); this.assert.notStrictEqual( first, diff --git a/packages/ember/index.js b/packages/ember/index.js index cb3191e9964..76febd1bef6 100644 --- a/packages/ember/index.js +++ b/packages/ember/index.js @@ -3,7 +3,6 @@ import require, { has } from 'require'; import { getENV, getLookup, setLookup } from '@ember/-internals/environment'; import * as utils from '@ember/-internals/utils'; import { Registry, Container } from '@ember/-internals/container'; -import { uniqueId } from '@ember/-internals/glimmer'; import * as instrumentation from '@ember/instrumentation'; import { meta } from '@ember/-internals/meta'; import * as metal from '@ember/-internals/metal'; @@ -428,7 +427,6 @@ Ember._concat = concat; Ember._get = get; Ember._on = on; Ember._fn = fn; -Ember._uniqueId = uniqueId; Ember._helperManagerCapabilities = helperCapabilities; Ember._setHelperManager = setHelperManager;