11/*
22 * An as yet uncategorized mishmash of helpers, relics of Karma
33 */
4- import * as LWC from 'lwc' ;
5- import {
6- ariaAttributes ,
7- ariaProperties ,
8- ariaPropertiesMapping ,
9- nonPolyfilledAriaProperties ,
10- nonStandardAriaProperties ,
11- } from './aria.js' ;
12- import { setHooks , getHooks } from './hooks.js' ;
13- import { spyConsole } from './console.js' ;
14- import {
15- DISABLE_OBJECT_REST_SPREAD_TRANSFORMATION ,
16- ENABLE_ELEMENT_INTERNALS_AND_FACE ,
17- ENABLE_THIS_DOT_HOST_ELEMENT ,
18- ENABLE_THIS_DOT_STYLE ,
19- IS_SYNTHETIC_SHADOW_LOADED ,
20- LOWERCASE_SCOPE_TOKENS ,
21- TEMPLATE_CLASS_NAME_OBJECT_BINDING ,
22- USE_COMMENTS_FOR_FRAGMENT_BOOKENDS ,
23- USE_FRAGMENTS_FOR_LIGHT_DOM_SLOTS ,
24- USE_LIGHT_DOM_SLOT_FORWARDING ,
25- } from './constants.js' ;
26- import { addTrustedSignal } from './signals.js' ;
4+ import { __unstable__ReportingControl } from 'lwc' ;
275
286// Listen for errors thrown directly by the callback
297function directErrorListener ( callback ) {
@@ -63,7 +41,7 @@ function windowErrorListener(callback) {
6341// 2) We're using native lifecycle callbacks, so the error is thrown asynchronously and can
6442// only be caught with window.addEventListener('error')
6543// - Note native lifecycle callbacks are all thrown asynchronously.
66- function customElementCallbackReactionErrorListener ( callback ) {
44+ export function customElementCallbackReactionErrorListener ( callback ) {
6745 return lwcRuntimeFlags . DISABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE
6846 ? directErrorListener ( callback )
6947 : windowErrorListener ( callback ) ;
@@ -74,19 +52,19 @@ function customElementCallbackReactionErrorListener(callback) {
7452 * @param dispatcher
7553 * @param runtimeEvents List of runtime events to filter by. If no list is provided, all events will be dispatched.
7654 */
77- function attachReportingControlDispatcher ( dispatcher , runtimeEvents ) {
78- LWC . __unstable__ReportingControl . attachDispatcher ( ( eventName , payload ) => {
55+ export function attachReportingControlDispatcher ( dispatcher , runtimeEvents ) {
56+ __unstable__ReportingControl . attachDispatcher ( ( eventName , payload ) => {
7957 if ( ! runtimeEvents || runtimeEvents . includes ( eventName ) ) {
8058 dispatcher ( eventName , payload ) ;
8159 }
8260 } ) ;
8361}
8462
85- function detachReportingControlDispatcher ( ) {
86- LWC . __unstable__ReportingControl . detachDispatcher ( ) ;
63+ export function detachReportingControlDispatcher ( ) {
64+ __unstable__ReportingControl . detachDispatcher ( ) ;
8765}
8866
89- function extractDataIds ( root ) {
67+ export function extractDataIds ( root ) {
9068 const nodes = { } ;
9169
9270 function processElement ( elm ) {
@@ -120,7 +98,7 @@ function extractDataIds(root) {
12098 return nodes ;
12199}
122100
123- function extractShadowDataIds ( shadowRoot ) {
101+ export function extractShadowDataIds ( shadowRoot ) {
124102 const nodes = { } ;
125103
126104 // Add the shadow root here even if they don't have [data-id] attributes. This reference is
@@ -140,36 +118,24 @@ function extractShadowDataIds(shadowRoot) {
140118 return nodes ;
141119}
142120
143- let register = { } ;
144- function load ( id ) {
145- return Promise . resolve ( register [ id ] ) ;
146- }
147-
148- function registerForLoad ( name , Ctor ) {
149- register [ name ] = Ctor ;
150- }
151- function clearRegister ( ) {
152- register = { } ;
153- }
154-
155121// #986 - childNodes on the host element returns a fake shadow comment node on IE11 for debugging purposes. This method
156122// filters this node.
157- function getHostChildNodes ( host ) {
123+ export function getHostChildNodes ( host ) {
158124 return Array . prototype . slice . call ( host . childNodes ) . filter ( function ( n ) {
159125 return ! ( n . nodeType === Node . COMMENT_NODE && n . tagName . startsWith ( '#shadow-root' ) ) ;
160126 } ) ;
161127}
162128
163- function isSyntheticShadowRootInstance ( sr ) {
129+ export function isSyntheticShadowRootInstance ( sr ) {
164130 return Boolean ( sr && sr . synthetic ) ;
165131}
166132
167- function isNativeShadowRootInstance ( sr ) {
133+ export function isNativeShadowRootInstance ( sr ) {
168134 return Boolean ( sr && ! sr . synthetic ) ;
169135}
170136
171137// Keep traversing up the prototype chain until a property descriptor is found
172- function getPropertyDescriptor ( object , prop ) {
138+ export function getPropertyDescriptor ( object , prop ) {
173139 do {
174140 const descriptor = Object . getOwnPropertyDescriptor ( object , prop ) ;
175141 if ( descriptor ) {
@@ -216,13 +182,13 @@ function stringifyArg(arg) {
216182 }
217183}
218184
219- const expectConsoleCalls = createExpectConsoleCallsFunc ( false ) ;
220- const expectConsoleCallsDev = createExpectConsoleCallsFunc ( true ) ;
185+ export const expectConsoleCalls = createExpectConsoleCallsFunc ( false ) ;
186+ export const expectConsoleCallsDev = createExpectConsoleCallsFunc ( true ) ;
221187
222188// Utility to handle unhandled rejections or errors without allowing Jasmine to handle them first.
223189// Captures both onunhandledrejection and onerror events, since you might want both depending on
224190// native vs synthetic lifecycle timing differences.
225- function catchUnhandledRejectionsAndErrors ( onUnhandledRejectionOrError ) {
191+ export function catchUnhandledRejectionsAndErrors ( onUnhandledRejectionOrError ) {
226192 let originalOnError ;
227193
228194 const onError = ( e ) => {
@@ -257,7 +223,7 @@ function catchUnhandledRejectionsAndErrors(onUnhandledRejectionOrError) {
257223
258224// Succeeds if the given DOM element is equivalent to the given HTML in terms of nodes and elements. This is
259225// basically the same as `expect(element.outerHTML).toBe(html)` except that it works despite bugs in synthetic shadow.
260- function expectEquivalentDOM ( element , html ) {
226+ export function expectEquivalentDOM ( element , html ) {
261227 const fragment = Document . parseHTMLUnsafe ( html ) ;
262228
263229 // When the fragment is parsed, the string "abc" is considered one text node. Whereas the engine
@@ -314,41 +280,3 @@ function expectEquivalentDOM(element, html) {
314280
315281 expectEquivalent ( element , fragment . body . firstChild ) ;
316282}
317-
318- export {
319- clearRegister ,
320- extractDataIds ,
321- extractShadowDataIds ,
322- getHostChildNodes ,
323- isNativeShadowRootInstance ,
324- isSyntheticShadowRootInstance ,
325- load ,
326- registerForLoad ,
327- getHooks ,
328- setHooks ,
329- spyConsole ,
330- customElementCallbackReactionErrorListener ,
331- ariaPropertiesMapping ,
332- ariaProperties ,
333- ariaAttributes ,
334- nonStandardAriaProperties ,
335- nonPolyfilledAriaProperties ,
336- getPropertyDescriptor ,
337- attachReportingControlDispatcher ,
338- detachReportingControlDispatcher ,
339- IS_SYNTHETIC_SHADOW_LOADED ,
340- expectConsoleCalls ,
341- expectConsoleCallsDev ,
342- catchUnhandledRejectionsAndErrors ,
343- addTrustedSignal ,
344- expectEquivalentDOM ,
345- LOWERCASE_SCOPE_TOKENS ,
346- USE_COMMENTS_FOR_FRAGMENT_BOOKENDS ,
347- USE_FRAGMENTS_FOR_LIGHT_DOM_SLOTS ,
348- DISABLE_OBJECT_REST_SPREAD_TRANSFORMATION ,
349- ENABLE_ELEMENT_INTERNALS_AND_FACE ,
350- USE_LIGHT_DOM_SLOT_FORWARDING ,
351- ENABLE_THIS_DOT_HOST_ELEMENT ,
352- ENABLE_THIS_DOT_STYLE ,
353- TEMPLATE_CLASS_NAME_OBJECT_BINDING ,
354- } ;
0 commit comments