How to use metaData method in storybook-root

Best JavaScript code snippet using storybook-root

Reflect.d.ts

Source:Reflect.d.ts Github

copy

Full Screen

1/*! *****************************************************************************2Copyright (C) Microsoft. All rights reserved.3Licensed under the Apache License, Version 2.0 (the "License"); you may not use4this file except in compliance with the License. You may obtain a copy of the5License at http://www.apache.org/licenses/LICENSE-2.067THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY8KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED9WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,10MERCHANTABLITY OR NON-INFRINGEMENT.1112See the Apache Version 2.0 License for specific language governing permissions13and limitations under the License.14***************************************************************************** */1516// NOTE: This file is obsolete and may be removed in a later release.17// For CommonJS/AMD/UMD/SystemJS declarations please use 'index.d.ts'.18// For standalone browser declarations, please use 'standalone.d.ts'.1920declare module "reflect-metadata" {21 // The "reflect-metadata" module has no imports or exports, but can be used by modules to load the polyfill.22}2324declare namespace Reflect {25 /**26 * Applies a set of decorators to a target object.27 * @param decorators An array of decorators.28 * @param target The target object.29 * @returns The result of applying the provided decorators.30 * @remarks Decorators are applied in reverse order of their positions in the array.31 * @example32 *33 * class Example { }34 *35 * // constructor36 * Example = Reflect.decorate(decoratorsArray, Example);37 *38 */39 function decorate(decorators: ClassDecorator[], target: Function): Function;40 /**41 * Applies a set of decorators to a property of a target object.42 * @param decorators An array of decorators.43 * @param target The target object.44 * @param targetKey The property key to decorate.45 * @param descriptor A property descriptor46 * @remarks Decorators are applied in reverse order.47 * @example48 *49 * class Example {50 * // property declarations are not part of ES6, though they are valid in TypeScript:51 * // static staticProperty;52 * // property;53 *54 * static staticMethod() { }55 * method() { }56 * }57 *58 * // property (on constructor)59 * Reflect.decorate(decoratorsArray, Example, "staticProperty");60 *61 * // property (on prototype)62 * Reflect.decorate(decoratorsArray, Example.prototype, "property");63 *64 * // method (on constructor)65 * Object.defineProperty(Example, "staticMethod",66 * Reflect.decorate(decoratorsArray, Example, "staticMethod",67 * Object.getOwnPropertyDescriptor(Example, "staticMethod")));68 *69 * // method (on prototype)70 * Object.defineProperty(Example.prototype, "method",71 * Reflect.decorate(decoratorsArray, Example.prototype, "method",72 * Object.getOwnPropertyDescriptor(Example.prototype, "method")));73 *74 */75 function decorate(decorators: (PropertyDecorator | MethodDecorator)[], target: Object, targetKey: string | symbol, descriptor?: PropertyDescriptor): PropertyDescriptor;76 /**77 * A default metadata decorator factory that can be used on a class, class member, or parameter.78 * @param metadataKey The key for the metadata entry.79 * @param metadataValue The value for the metadata entry.80 * @returns A decorator function.81 * @remarks82 * If `metadataKey` is already defined for the target and target key, the83 * metadataValue for that key will be overwritten.84 * @example85 *86 * // constructor87 * @Reflect.metadata(key, value)88 * class Example {89 * }90 *91 * // property (on constructor, TypeScript only)92 * class Example {93 * @Reflect.metadata(key, value)94 * static staticProperty;95 * }96 *97 * // property (on prototype, TypeScript only)98 * class Example {99 * @Reflect.metadata(key, value)100 * property;101 * }102 *103 * // method (on constructor)104 * class Example {105 * @Reflect.metadata(key, value)106 * static staticMethod() { }107 * }108 *109 * // method (on prototype)110 * class Example {111 * @Reflect.metadata(key, value)112 * method() { }113 * }114 *115 */116 function metadata(metadataKey: any, metadataValue: any): {117 (target: Function): void;118 (target: Object, targetKey: string | symbol): void;119 };120 /**121 * Define a unique metadata entry on the target.122 * @param metadataKey A key used to store and retrieve metadata.123 * @param metadataValue A value that contains attached metadata.124 * @param target The target object on which to define metadata.125 * @example126 *127 * class Example {128 * }129 *130 * // constructor131 * Reflect.defineMetadata("custom:annotation", options, Example);132 *133 * // decorator factory as metadata-producing annotation.134 * function MyAnnotation(options): ClassDecorator {135 * return target => Reflect.defineMetadata("custom:annotation", options, target);136 * }137 *138 */139 function defineMetadata(metadataKey: any, metadataValue: any, target: Object): void;140 /**141 * Define a unique metadata entry on the target.142 * @param metadataKey A key used to store and retrieve metadata.143 * @param metadataValue A value that contains attached metadata.144 * @param target The target object on which to define metadata.145 * @param targetKey The property key for the target.146 * @example147 *148 * class Example {149 * // property declarations are not part of ES6, though they are valid in TypeScript:150 * // static staticProperty;151 * // property;152 *153 * static staticMethod(p) { }154 * method(p) { }155 * }156 *157 * // property (on constructor)158 * Reflect.defineMetadata("custom:annotation", Number, Example, "staticProperty");159 *160 * // property (on prototype)161 * Reflect.defineMetadata("custom:annotation", Number, Example.prototype, "property");162 *163 * // method (on constructor)164 * Reflect.defineMetadata("custom:annotation", Number, Example, "staticMethod");165 *166 * // method (on prototype)167 * Reflect.defineMetadata("custom:annotation", Number, Example.prototype, "method");168 *169 * // decorator factory as metadata-producing annotation.170 * function MyAnnotation(options): PropertyDecorator {171 * return (target, key) => Reflect.defineMetadata("custom:annotation", options, target, key);172 * }173 *174 */175 function defineMetadata(metadataKey: any, metadataValue: any, target: Object, targetKey: string | symbol): void;176 /**177 * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined.178 * @param metadataKey A key used to store and retrieve metadata.179 * @param target The target object on which the metadata is defined.180 * @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`.181 * @example182 *183 * class Example {184 * }185 *186 * // constructor187 * result = Reflect.hasMetadata("custom:annotation", Example);188 *189 */190 function hasMetadata(metadataKey: any, target: Object): boolean;191 /**192 * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined.193 * @param metadataKey A key used to store and retrieve metadata.194 * @param target The target object on which the metadata is defined.195 * @param targetKey The property key for the target.196 * @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`.197 * @example198 *199 * class Example {200 * // property declarations are not part of ES6, though they are valid in TypeScript:201 * // static staticProperty;202 * // property;203 *204 * static staticMethod(p) { }205 * method(p) { }206 * }207 *208 * // property (on constructor)209 * result = Reflect.hasMetadata("custom:annotation", Example, "staticProperty");210 *211 * // property (on prototype)212 * result = Reflect.hasMetadata("custom:annotation", Example.prototype, "property");213 *214 * // method (on constructor)215 * result = Reflect.hasMetadata("custom:annotation", Example, "staticMethod");216 *217 * // method (on prototype)218 * result = Reflect.hasMetadata("custom:annotation", Example.prototype, "method");219 *220 */221 function hasMetadata(metadataKey: any, target: Object, targetKey: string | symbol): boolean;222 /**223 * Gets a value indicating whether the target object has the provided metadata key defined.224 * @param metadataKey A key used to store and retrieve metadata.225 * @param target The target object on which the metadata is defined.226 * @returns `true` if the metadata key was defined on the target object; otherwise, `false`.227 * @example228 *229 * class Example {230 * }231 *232 * // constructor233 * result = Reflect.hasOwnMetadata("custom:annotation", Example);234 *235 */236 function hasOwnMetadata(metadataKey: any, target: Object): boolean;237 /**238 * Gets a value indicating whether the target object has the provided metadata key defined.239 * @param metadataKey A key used to store and retrieve metadata.240 * @param target The target object on which the metadata is defined.241 * @param targetKey The property key for the target.242 * @returns `true` if the metadata key was defined on the target object; otherwise, `false`.243 * @example244 *245 * class Example {246 * // property declarations are not part of ES6, though they are valid in TypeScript:247 * // static staticProperty;248 * // property;249 *250 * static staticMethod(p) { }251 * method(p) { }252 * }253 *254 * // property (on constructor)255 * result = Reflect.hasOwnMetadata("custom:annotation", Example, "staticProperty");256 *257 * // property (on prototype)258 * result = Reflect.hasOwnMetadata("custom:annotation", Example.prototype, "property");259 *260 * // method (on constructor)261 * result = Reflect.hasOwnMetadata("custom:annotation", Example, "staticMethod");262 *263 * // method (on prototype)264 * result = Reflect.hasOwnMetadata("custom:annotation", Example.prototype, "method");265 *266 */267 function hasOwnMetadata(metadataKey: any, target: Object, targetKey: string | symbol): boolean;268 /**269 * Gets the metadata value for the provided metadata key on the target object or its prototype chain.270 * @param metadataKey A key used to store and retrieve metadata.271 * @param target The target object on which the metadata is defined.272 * @returns The metadata value for the metadata key if found; otherwise, `undefined`.273 * @example274 *275 * class Example {276 * }277 *278 * // constructor279 * result = Reflect.getMetadata("custom:annotation", Example);280 *281 */282 function getMetadata(metadataKey: any, target: Object): any;283 /**284 * Gets the metadata value for the provided metadata key on the target object or its prototype chain.285 * @param metadataKey A key used to store and retrieve metadata.286 * @param target The target object on which the metadata is defined.287 * @param targetKey The property key for the target.288 * @returns The metadata value for the metadata key if found; otherwise, `undefined`.289 * @example290 *291 * class Example {292 * // property declarations are not part of ES6, though they are valid in TypeScript:293 * // static staticProperty;294 * // property;295 *296 * static staticMethod(p) { }297 * method(p) { }298 * }299 *300 * // property (on constructor)301 * result = Reflect.getMetadata("custom:annotation", Example, "staticProperty");302 *303 * // property (on prototype)304 * result = Reflect.getMetadata("custom:annotation", Example.prototype, "property");305 *306 * // method (on constructor)307 * result = Reflect.getMetadata("custom:annotation", Example, "staticMethod");308 *309 * // method (on prototype)310 * result = Reflect.getMetadata("custom:annotation", Example.prototype, "method");311 *312 */313 function getMetadata(metadataKey: any, target: Object, targetKey: string | symbol): any;314 /**315 * Gets the metadata value for the provided metadata key on the target object.316 * @param metadataKey A key used to store and retrieve metadata.317 * @param target The target object on which the metadata is defined.318 * @returns The metadata value for the metadata key if found; otherwise, `undefined`.319 * @example320 *321 * class Example {322 * }323 *324 * // constructor325 * result = Reflect.getOwnMetadata("custom:annotation", Example);326 *327 */328 function getOwnMetadata(metadataKey: any, target: Object): any;329 /**330 * Gets the metadata value for the provided metadata key on the target object.331 * @param metadataKey A key used to store and retrieve metadata.332 * @param target The target object on which the metadata is defined.333 * @param targetKey The property key for the target.334 * @returns The metadata value for the metadata key if found; otherwise, `undefined`.335 * @example336 *337 * class Example {338 * // property declarations are not part of ES6, though they are valid in TypeScript:339 * // static staticProperty;340 * // property;341 *342 * static staticMethod(p) { }343 * method(p) { }344 * }345 *346 * // property (on constructor)347 * result = Reflect.getOwnMetadata("custom:annotation", Example, "staticProperty");348 *349 * // property (on prototype)350 * result = Reflect.getOwnMetadata("custom:annotation", Example.prototype, "property");351 *352 * // method (on constructor)353 * result = Reflect.getOwnMetadata("custom:annotation", Example, "staticMethod");354 *355 * // method (on prototype)356 * result = Reflect.getOwnMetadata("custom:annotation", Example.prototype, "method");357 *358 */359 function getOwnMetadata(metadataKey: any, target: Object, targetKey: string | symbol): any;360 /**361 * Gets the metadata keys defined on the target object or its prototype chain.362 * @param target The target object on which the metadata is defined.363 * @returns An array of unique metadata keys.364 * @example365 *366 * class Example {367 * }368 *369 * // constructor370 * result = Reflect.getMetadataKeys(Example);371 *372 */373 function getMetadataKeys(target: Object): any[];374 /**375 * Gets the metadata keys defined on the target object or its prototype chain.376 * @param target The target object on which the metadata is defined.377 * @param targetKey The property key for the target.378 * @returns An array of unique metadata keys.379 * @example380 *381 * class Example {382 * // property declarations are not part of ES6, though they are valid in TypeScript:383 * // static staticProperty;384 * // property;385 *386 * static staticMethod(p) { }387 * method(p) { }388 * }389 *390 * // property (on constructor)391 * result = Reflect.getMetadataKeys(Example, "staticProperty");392 *393 * // property (on prototype)394 * result = Reflect.getMetadataKeys(Example.prototype, "property");395 *396 * // method (on constructor)397 * result = Reflect.getMetadataKeys(Example, "staticMethod");398 *399 * // method (on prototype)400 * result = Reflect.getMetadataKeys(Example.prototype, "method");401 *402 */403 function getMetadataKeys(target: Object, targetKey: string | symbol): any[];404 /**405 * Gets the unique metadata keys defined on the target object.406 * @param target The target object on which the metadata is defined.407 * @returns An array of unique metadata keys.408 * @example409 *410 * class Example {411 * }412 *413 * // constructor414 * result = Reflect.getOwnMetadataKeys(Example);415 *416 */417 function getOwnMetadataKeys(target: Object): any[];418 /**419 * Gets the unique metadata keys defined on the target object.420 * @param target The target object on which the metadata is defined.421 * @param targetKey The property key for the target.422 * @returns An array of unique metadata keys.423 * @example424 *425 * class Example {426 * // property declarations are not part of ES6, though they are valid in TypeScript:427 * // static staticProperty;428 * // property;429 *430 * static staticMethod(p) { }431 * method(p) { }432 * }433 *434 * // property (on constructor)435 * result = Reflect.getOwnMetadataKeys(Example, "staticProperty");436 *437 * // property (on prototype)438 * result = Reflect.getOwnMetadataKeys(Example.prototype, "property");439 *440 * // method (on constructor)441 * result = Reflect.getOwnMetadataKeys(Example, "staticMethod");442 *443 * // method (on prototype)444 * result = Reflect.getOwnMetadataKeys(Example.prototype, "method");445 *446 */447 function getOwnMetadataKeys(target: Object, targetKey: string | symbol): any[];448 /**449 * Deletes the metadata entry from the target object with the provided key.450 * @param metadataKey A key used to store and retrieve metadata.451 * @param target The target object on which the metadata is defined.452 * @returns `true` if the metadata entry was found and deleted; otherwise, false.453 * @example454 *455 * class Example {456 * }457 *458 * // constructor459 * result = Reflect.deleteMetadata("custom:annotation", Example);460 *461 */462 function deleteMetadata(metadataKey: any, target: Object): boolean;463 /**464 * Deletes the metadata entry from the target object with the provided key.465 * @param metadataKey A key used to store and retrieve metadata.466 * @param target The target object on which the metadata is defined.467 * @param targetKey The property key for the target.468 * @returns `true` if the metadata entry was found and deleted; otherwise, false.469 * @example470 *471 * class Example {472 * // property declarations are not part of ES6, though they are valid in TypeScript:473 * // static staticProperty;474 * // property;475 *476 * static staticMethod(p) { }477 * method(p) { }478 * }479 *480 * // property (on constructor)481 * result = Reflect.deleteMetadata("custom:annotation", Example, "staticProperty");482 *483 * // property (on prototype)484 * result = Reflect.deleteMetadata("custom:annotation", Example.prototype, "property");485 *486 * // method (on constructor)487 * result = Reflect.deleteMetadata("custom:annotation", Example, "staticMethod");488 *489 * // method (on prototype)490 * result = Reflect.deleteMetadata("custom:annotation", Example.prototype, "method");491 *492 */493 function deleteMetadata(metadataKey: any, target: Object, targetKey: string | symbol): boolean; ...

Full Screen

Full Screen

parseSourceAndMetadata.js

Source:parseSourceAndMetadata.js Github

copy

Full Screen

1/**2 * Copyright (c) Facebook, Inc. and its affiliates.3 *4 * This source code is licensed under the MIT license found in the5 * LICENSE file in the root directory of this source tree.6 *7 * @flow8 */9// For an overview of why the code in this file is structured this way,10// refer to header comments in loadSourceAndMetadata.11import {parse} from '@babel/parser';12import LRU from 'lru-cache';13import {getHookName} from '../astUtils';14import {areSourceMapsAppliedToErrors} from '../ErrorTester';15import {__DEBUG__} from 'react-devtools-shared/src/constants';16import {getHookSourceLocationKey} from 'react-devtools-shared/src/hookNamesCache';17import {SourceMapMetadataConsumer} from '../SourceMapMetadataConsumer';18import {19 withAsyncPerfMeasurements,20 withSyncPerfMeasurements,21} from 'react-devtools-shared/src/PerformanceLoggingUtils';22import SourceMapConsumer from '../SourceMapConsumer';23import type {SourceMapConsumerType} from '../SourceMapConsumer';24import type {25 HooksList,26 LocationKeyToHookSourceAndMetadata,27} from './loadSourceAndMetadata';28import type {HookSource} from 'react-debug-tools/src/ReactDebugHooks';29import type {HookNames, LRUCache} from 'react-devtools-shared/src/types';30type AST = mixed;31type HookParsedMetadata = {|32 // API for consuming metadfata present in extended source map.33 metadataConsumer: SourceMapMetadataConsumer | null,34 // AST for original source code; typically comes from a consumed source map.35 originalSourceAST: AST | null,36 // Source code (React components or custom hooks) containing primitive hook calls.37 // If no source map has been provided, this code will be the same as runtimeSourceCode.38 originalSourceCode: string | null,39 // Original source URL if there is a source map, or the same as runtimeSourceURL.40 originalSourceURL: string | null,41 // Line number in original source code.42 originalSourceLineNumber: number | null,43 // Column number in original source code.44 originalSourceColumnNumber: number | null,45 // Alternate APIs from source-map for parsing source maps (if detected).46 sourceMapConsumer: SourceMapConsumerType | null,47|};48type LocationKeyToHookParsedMetadata = Map<string, HookParsedMetadata>;49type CachedRuntimeCodeMetadata = {|50 metadataConsumer: SourceMapMetadataConsumer | null,51 sourceMapConsumer: SourceMapConsumerType | null,52|};53const runtimeURLToMetadataCache: LRUCache<54 string,55 CachedRuntimeCodeMetadata,56> = new LRU({max: 50});57type CachedSourceCodeMetadata = {|58 originalSourceAST: AST,59 originalSourceCode: string,60|};61const originalURLToMetadataCache: LRUCache<62 string,63 CachedSourceCodeMetadata,64> = new LRU({65 max: 50,66 dispose: (originalSourceURL: string, metadata: CachedSourceCodeMetadata) => {67 if (__DEBUG__) {68 console.log(69 `originalURLToMetadataCache.dispose() Evicting cached metadata for "${originalSourceURL}"`,70 );71 }72 },73});74export async function parseSourceAndMetadata(75 hooksList: HooksList,76 locationKeyToHookSourceAndMetadata: LocationKeyToHookSourceAndMetadata,77): Promise<HookNames | null> {78 return withAsyncPerfMeasurements('parseSourceAndMetadata()', async () => {79 const locationKeyToHookParsedMetadata = withSyncPerfMeasurements(80 'initializeHookParsedMetadata',81 () => initializeHookParsedMetadata(locationKeyToHookSourceAndMetadata),82 );83 withSyncPerfMeasurements('parseSourceMaps', () =>84 parseSourceMaps(85 locationKeyToHookSourceAndMetadata,86 locationKeyToHookParsedMetadata,87 ),88 );89 withSyncPerfMeasurements('parseSourceAST()', () =>90 parseSourceAST(91 locationKeyToHookSourceAndMetadata,92 locationKeyToHookParsedMetadata,93 ),94 );95 return withSyncPerfMeasurements('findHookNames()', () =>96 findHookNames(hooksList, locationKeyToHookParsedMetadata),97 );98 });99}100function findHookNames(101 hooksList: HooksList,102 locationKeyToHookParsedMetadata: LocationKeyToHookParsedMetadata,103): HookNames {104 const map: HookNames = new Map();105 hooksList.map(hook => {106 // We already guard against a null HookSource in parseHookNames()107 const hookSource = ((hook.hookSource: any): HookSource);108 const fileName = hookSource.fileName;109 if (!fileName) {110 return null; // Should not be reachable.111 }112 const locationKey = getHookSourceLocationKey(hookSource);113 const hookParsedMetadata = locationKeyToHookParsedMetadata.get(locationKey);114 if (!hookParsedMetadata) {115 return null; // Should not be reachable.116 }117 const {lineNumber, columnNumber} = hookSource;118 if (!lineNumber || !columnNumber) {119 return null; // Should not be reachable.120 }121 const {122 originalSourceURL,123 originalSourceColumnNumber,124 originalSourceLineNumber,125 } = hookParsedMetadata;126 if (127 originalSourceLineNumber == null ||128 originalSourceColumnNumber == null ||129 originalSourceURL == null130 ) {131 return null; // Should not be reachable.132 }133 let name;134 const {metadataConsumer} = hookParsedMetadata;135 if (metadataConsumer != null) {136 name = withSyncPerfMeasurements('metadataConsumer.hookNameFor()', () =>137 metadataConsumer.hookNameFor({138 line: originalSourceLineNumber,139 column: originalSourceColumnNumber,140 source: originalSourceURL,141 }),142 );143 }144 if (name == null) {145 name = withSyncPerfMeasurements('getHookName()', () =>146 getHookName(147 hook,148 hookParsedMetadata.originalSourceAST,149 ((hookParsedMetadata.originalSourceCode: any): string),150 ((originalSourceLineNumber: any): number),151 originalSourceColumnNumber,152 ),153 );154 }155 if (__DEBUG__) {156 console.log(`findHookNames() Found name "${name || '-'}"`);157 }158 const key = getHookSourceLocationKey(hookSource);159 map.set(key, name);160 });161 return map;162}163function initializeHookParsedMetadata(164 locationKeyToHookSourceAndMetadata: LocationKeyToHookSourceAndMetadata,165) {166 // Create map of unique source locations (file names plus line and column numbers) to metadata about hooks.167 const locationKeyToHookParsedMetadata: LocationKeyToHookParsedMetadata = new Map();168 locationKeyToHookSourceAndMetadata.forEach(169 (hookSourceAndMetadata, locationKey) => {170 const hookParsedMetadata: HookParsedMetadata = {171 metadataConsumer: null,172 originalSourceAST: null,173 originalSourceCode: null,174 originalSourceURL: null,175 originalSourceLineNumber: null,176 originalSourceColumnNumber: null,177 sourceMapConsumer: null,178 };179 locationKeyToHookParsedMetadata.set(locationKey, hookParsedMetadata);180 },181 );182 return locationKeyToHookParsedMetadata;183}184function parseSourceAST(185 locationKeyToHookSourceAndMetadata: LocationKeyToHookSourceAndMetadata,186 locationKeyToHookParsedMetadata: LocationKeyToHookParsedMetadata,187): void {188 locationKeyToHookSourceAndMetadata.forEach(189 (hookSourceAndMetadata, locationKey) => {190 const hookParsedMetadata = locationKeyToHookParsedMetadata.get(191 locationKey,192 );193 if (hookParsedMetadata == null) {194 throw Error(`Expected to find HookParsedMetadata for "${locationKey}"`);195 }196 if (hookParsedMetadata.originalSourceAST !== null) {197 // Use cached metadata.198 return;199 }200 if (201 hookParsedMetadata.originalSourceURL != null &&202 hookParsedMetadata.originalSourceCode != null &&203 hookParsedMetadata.originalSourceColumnNumber != null &&204 hookParsedMetadata.originalSourceLineNumber != null205 ) {206 // Use cached metadata.207 return;208 }209 const {lineNumber, columnNumber} = hookSourceAndMetadata.hookSource;210 if (lineNumber == null || columnNumber == null) {211 throw Error('Hook source code location not found.');212 }213 const {metadataConsumer, sourceMapConsumer} = hookParsedMetadata;214 const runtimeSourceCode = ((hookSourceAndMetadata.runtimeSourceCode: any): string);215 let hasHookMap = false;216 let originalSourceURL;217 let originalSourceCode;218 let originalSourceColumnNumber;219 let originalSourceLineNumber;220 if (areSourceMapsAppliedToErrors() || sourceMapConsumer === null) {221 // Either the current environment automatically applies source maps to errors,222 // or the current code had no source map to begin with.223 // Either way, we don't need to convert the Error stack frame locations.224 originalSourceColumnNumber = columnNumber;225 originalSourceLineNumber = lineNumber;226 // There's no source map to parse here so we can just parse the original source itself.227 originalSourceCode = runtimeSourceCode;228 // TODO (named hooks) This mixes runtimeSourceURLs with source mapped URLs in the same cache key space.229 // Namespace them?230 originalSourceURL = hookSourceAndMetadata.runtimeSourceURL;231 } else {232 const {233 column,234 line,235 sourceContent,236 sourceURL,237 } = sourceMapConsumer.originalPositionFor({238 columnNumber,239 lineNumber,240 });241 originalSourceColumnNumber = column;242 originalSourceLineNumber = line;243 originalSourceCode = sourceContent;244 originalSourceURL = sourceURL;245 }246 hookParsedMetadata.originalSourceCode = originalSourceCode;247 hookParsedMetadata.originalSourceURL = originalSourceURL;248 hookParsedMetadata.originalSourceLineNumber = originalSourceLineNumber;249 hookParsedMetadata.originalSourceColumnNumber = originalSourceColumnNumber;250 if (251 metadataConsumer != null &&252 metadataConsumer.hasHookMap(originalSourceURL)253 ) {254 hasHookMap = true;255 }256 if (__DEBUG__) {257 console.log(258 `parseSourceAST() mapped line ${lineNumber}->${originalSourceLineNumber} and column ${columnNumber}->${originalSourceColumnNumber}`,259 );260 }261 if (hasHookMap) {262 if (__DEBUG__) {263 console.log(264 `parseSourceAST() Found hookMap and skipping parsing for "${originalSourceURL}"`,265 );266 }267 // If there's a hook map present from an extended sourcemap then268 // we don't need to parse the source files and instead can use the269 // hook map to extract hook names.270 return;271 }272 if (__DEBUG__) {273 console.log(274 `parseSourceAST() Did not find hook map for "${originalSourceURL}"`,275 );276 }277 // The cache also serves to deduplicate parsing by URL in our loop over location keys.278 // This may need to change if we switch to async parsing.279 const sourceMetadata = originalURLToMetadataCache.get(originalSourceURL);280 if (sourceMetadata != null) {281 if (__DEBUG__) {282 console.groupCollapsed(283 `parseSourceAST() Found cached source metadata for "${originalSourceURL}"`,284 );285 console.log(sourceMetadata);286 console.groupEnd();287 }288 hookParsedMetadata.originalSourceAST = sourceMetadata.originalSourceAST;289 hookParsedMetadata.originalSourceCode =290 sourceMetadata.originalSourceCode;291 } else {292 try {293 // TypeScript is the most commonly used typed JS variant so let's default to it294 // unless we detect explicit Flow usage via the "@flow" pragma.295 const plugin =296 originalSourceCode.indexOf('@flow') > 0 ? 'flow' : 'typescript';297 // TODO (named hooks) This is probably where we should check max source length,298 // rather than in loadSourceAndMetatada -> loadSourceFiles().299 // TODO(#22319): Support source files that are html files with inline script tags.300 const originalSourceAST = withSyncPerfMeasurements(301 '[@babel/parser] parse(originalSourceCode)',302 () =>303 parse(originalSourceCode, {304 sourceType: 'unambiguous',305 plugins: ['jsx', plugin],306 }),307 );308 hookParsedMetadata.originalSourceAST = originalSourceAST;309 if (__DEBUG__) {310 console.log(311 `parseSourceAST() Caching source metadata for "${originalSourceURL}"`,312 );313 }314 originalURLToMetadataCache.set(originalSourceURL, {315 originalSourceAST,316 originalSourceCode,317 });318 } catch (error) {319 throw new Error(320 `Failed to parse source file: ${originalSourceURL}\n\n` +321 `Original error: ${error}`,322 );323 }324 }325 },326 );327}328function parseSourceMaps(329 locationKeyToHookSourceAndMetadata: LocationKeyToHookSourceAndMetadata,330 locationKeyToHookParsedMetadata: LocationKeyToHookParsedMetadata,331) {332 locationKeyToHookSourceAndMetadata.forEach(333 (hookSourceAndMetadata, locationKey) => {334 const hookParsedMetadata = locationKeyToHookParsedMetadata.get(335 locationKey,336 );337 if (hookParsedMetadata == null) {338 throw Error(`Expected to find HookParsedMetadata for "${locationKey}"`);339 }340 const {runtimeSourceURL, sourceMapJSON} = hookSourceAndMetadata;341 // If we've already loaded the source map info for this file,342 // we can skip reloading it (and more importantly, re-parsing it).343 const runtimeMetadata = runtimeURLToMetadataCache.get(runtimeSourceURL);344 if (runtimeMetadata != null) {345 if (__DEBUG__) {346 console.groupCollapsed(347 `parseHookNames() Found cached runtime metadata for file "${runtimeSourceURL}"`,348 );349 console.log(runtimeMetadata);350 console.groupEnd();351 }352 hookParsedMetadata.metadataConsumer = runtimeMetadata.metadataConsumer;353 hookParsedMetadata.sourceMapConsumer =354 runtimeMetadata.sourceMapConsumer;355 } else {356 if (sourceMapJSON != null) {357 const sourceMapConsumer = withSyncPerfMeasurements(358 'new SourceMapConsumer(sourceMapJSON)',359 () => SourceMapConsumer(sourceMapJSON),360 );361 const metadataConsumer = withSyncPerfMeasurements(362 'new SourceMapMetadataConsumer(sourceMapJSON)',363 () => new SourceMapMetadataConsumer(sourceMapJSON),364 );365 hookParsedMetadata.metadataConsumer = metadataConsumer;366 hookParsedMetadata.sourceMapConsumer = sourceMapConsumer;367 // Only set once to avoid triggering eviction/cleanup code.368 runtimeURLToMetadataCache.set(runtimeSourceURL, {369 metadataConsumer: metadataConsumer,370 sourceMapConsumer: sourceMapConsumer,371 });372 }373 }374 },375 );376}377export function purgeCachedMetadata(): void {378 originalURLToMetadataCache.reset();379 runtimeURLToMetadataCache.reset();...

Full Screen

Full Screen

MetadataManagerSpec.js

Source:MetadataManagerSpec.js Github

copy

Full Screen

1define(["sap/watt/ideplatform/backend/util/MetadataManager"], function (oMetadataManager) {2 3 "use strict";4 5 describe("Metadata Manager test", function() { 6 7 it("configure", function() {8 assert.ok(oMetadataManager.hasChildren(undefined) === false);9 assert.ok(oMetadataManager.hasChildren(null) === false);10 assert.ok(oMetadataManager.hasChildren("") === false);11 assert.ok(oMetadataManager.hasChildren("project") === false);12 assert.ok(oMetadataManager.hasChildren("/project") === false);13 // create project with folder and file14 var oProjectMetadata = {};15 oProjectMetadata["/project"] = {name : "project1"};16 oProjectMetadata["/project/folder"] = {name : "folder1"};17 oProjectMetadata["/project/folder/file.txt"] = {name : "file.txt"};18 oMetadataManager.setMetadata(oProjectMetadata);19 assert.ok(oMetadataManager.hasChildren("/project") === true);20 assert.ok(oMetadataManager.hasChildren("/project/folder") === true);21 assert.ok(oMetadataManager.hasChildren("/project/folder/file.txt") === false);22 });23 24 it("_getProjectPath", function() {25 assert.ok(oMetadataManager._getProjectPath(undefined) === undefined);26 assert.ok(oMetadataManager._getProjectPath(null) === undefined);27 assert.ok(oMetadataManager._getProjectPath("") === "");28 assert.ok(oMetadataManager._getProjectPath("project") === undefined);29 assert.ok(oMetadataManager._getProjectPath("/project") === "/project");30 assert.ok(oMetadataManager._getProjectPath("/project/folder") === "/project");31 assert.ok(oMetadataManager._getProjectPath("/project/folder/") === "/project");32 assert.ok(oMetadataManager._getProjectPath("/project/folder/file.txt") === "/project");33 assert.ok(oMetadataManager._getProjectPath("/project/folder/file.txt/") === "/project");34 });35 36 it("deleteMetadata", function() {37 // must not fail38 assert.ok(oMetadataManager.deleteMetadata(undefined) === undefined);39 assert.ok(oMetadataManager.deleteMetadata(null) === undefined);40 assert.ok(oMetadataManager.deleteMetadata("project") === undefined);41 assert.ok(oMetadataManager.deleteMetadata("/project") === undefined);42 assert.ok(oMetadataManager.deleteMetadata("/project/folder") === undefined);43 assert.ok(oMetadataManager.deleteMetadata("/project/folder/file.txt") === undefined);44 // create project with folder and file and delete file45 var oProjectMetadata = {};46 oProjectMetadata["/project"] = {name : "project1"};47 oProjectMetadata["/project/folder"] = {name : "folder1"};48 oProjectMetadata["/project/folder/file.txt"] = {name : "file.txt"};49 oMetadataManager.setMetadata(oProjectMetadata);50 // delete file51 oMetadataManager.deleteMetadata("/project/folder/file.txt");52 assert.ok(oMetadataManager.getMetadata("/project/folder/file.txt") === undefined);53 assert.ok(oMetadataManager.getMetadata("/project/folder").name === "folder1");54 assert.ok(oMetadataManager.getMetadata("/project").name === "project1");55 // create project with folder and file and delete folder56 var oProjectMetadata = {};57 oProjectMetadata["/project"] = {name : "project1"};58 oProjectMetadata["/project/folder"] = {name : "folder1"};59 oProjectMetadata["/project/folder/file.txt"] = {name : "file.txt"};60 oMetadataManager.setMetadata(oProjectMetadata);61 // delete folder62 oMetadataManager.deleteMetadata("/project/folder", true);63 assert.ok(oMetadataManager.getMetadata("/project/folder") === undefined);64 assert.ok(oMetadataManager.getMetadata("/project/folder/file.txt") === undefined);65 assert.ok(oMetadataManager.getMetadata("/project").name === "project1");66 // create project with folder and file and delete project67 var oProjectMetadata = {};68 oProjectMetadata["/project"] = {name : "project1"};69 oProjectMetadata["/project/folder"] = {name : "folder1"};70 oProjectMetadata["/project/folder/file.txt"] = {name : "file.txt"};71 oMetadataManager.setMetadata(oProjectMetadata);72 // delete project73 oMetadataManager.deleteMetadata("/project", true);74 assert.ok(oMetadataManager.getMetadata("/project") === undefined);75 assert.ok(oMetadataManager.getMetadata("/project/folder") === undefined);76 assert.ok(oMetadataManager.getMetadata("/project/folder/file.txt") === undefined);77 });78 79 it("setMetadata", function() {80 // must pass without errors81 assert.ok(oMetadataManager.setMetadata() === undefined);82 assert.ok(oMetadataManager.setMetadata(null) === undefined);83 // set with empty object84 oMetadataManager.setMetadata({"/project" : {}});85 assert.ok(oMetadataManager.getMetadata("/project") !== undefined);86 oMetadataManager.deleteMetadata("/project");87 assert.ok(oMetadataManager.getMetadata("/project") === undefined);88 // set with non empty object89 oMetadataManager.setMetadata({"/project/folder" : {"property1" : "value1"}});90 assert.ok(oMetadataManager.getMetadata("/project/folder").property1 === "value1");91 // check that object is updated92 oMetadataManager.setMetadata({"/project/folder" : {"property1" : "value2"}});93 assert.ok(oMetadataManager.getMetadata("/project/folder").property1 === "value2");94 // add one more value95 oMetadataManager.setMetadata({"/project/folder2" : {"property2" : "value3"}});96 assert.ok(oMetadataManager.getMetadata("/project/folder2").property2 === "value3");97 // add one project with folder98 oMetadataManager.setMetadata({"/project2/folder" : {"property1" : "value4"}});99 assert.ok(oMetadataManager.getMetadata("/project2/folder").property1 === "value4");100 oMetadataManager.deleteMetadata("/project");101 });102 103 it("getMetadata", function() {104 // must not fail105 assert.ok(oMetadataManager.getMetadata(undefined) === undefined);106 assert.ok(oMetadataManager.getMetadata(null) === undefined);107 assert.ok(oMetadataManager.getMetadata("project") === undefined);108 assert.ok(oMetadataManager.getMetadata("/project") === undefined);109 assert.ok(oMetadataManager.getMetadata("/project/folder") === undefined);110 assert.ok(oMetadataManager.getMetadata("/project/folder/file.txt") === undefined);111 // create project with folder and file and get them one by one112 var oProjectMetadata = {};113 oProjectMetadata["/project"] = {name : "project1"};114 oProjectMetadata["/project/folder"] = {name : "folder1"};115 oProjectMetadata["/project/folder/file.txt"] = {name : "file.txt"};116 oMetadataManager.setMetadata(oProjectMetadata);117 // get project data118 assert.ok(oMetadataManager.getMetadata("/project").name === "project1");119 assert.ok(oMetadataManager.getMetadata("/project/folder").name === "folder1");120 assert.ok(oMetadataManager.getMetadata("/project/folder/file.txt").name === "file.txt");121 oMetadataManager.deleteMetadata("/project");122 });123 124 it("_getRootProjectsMetadata", function() {125 // must not fail126 assert.ok(oMetadataManager.getMetadata("") !== undefined);127 // create project1 with folder and file128 var oProjectMetadata = {};129 oProjectMetadata["/project1"] = {name : "project1"};130 oProjectMetadata["/project1/folder"] = {name : "folder1"};131 oProjectMetadata["/project1/folder/file.txt"] = {name : "file.txt"};132 oMetadataManager.setMetadata(oProjectMetadata);133 // create project2 with folder and file134 var oProjectMetadata2 = {};135 oProjectMetadata2["/project2"] = {name : "project2"};136 oProjectMetadata2["/project2/folder"] = {name : "folder2"};137 oProjectMetadata2["/project2/folder/file.txt"] = {name : "file.txt"};138 oMetadataManager.setMetadata(oProjectMetadata2);139 // get root projects metadata140 var oRootProjectsMetadata = oMetadataManager.getMetadata("");141 var aProjectPathes = Object.keys(oRootProjectsMetadata);142 assert.ok(aProjectPathes.length === 2);143 });144 });...

Full Screen

Full Screen

metadata.js

Source:metadata.js Github

copy

Full Screen

1var fs = require('fs');2var file = require('file');3var marked = require('marked');4var polyfills = require('./polyfills.json');5var viewRoot = fs.realpathSync(__dirname + '/../feature-detects');6function metadata(cb) {7 var tests = [];8 file.walkSync(viewRoot, function(start, dirs, files) {9 files.forEach(function(file) {10 if (file === '.DS_Store') {11 return;12 }13 var test = fs.readFileSync(start + '/' + file, 'utf8');14 // TODO :: make this regex not suck15 var metaRE = /\/\*\!([\s\S]*)\!\*\//m;16 var matches = test.match(metaRE);17 var docRE = /\/\*\sDOC([\s\S]*?)\*\//m;18 var docmatches = test.match(docRE);19 var depRE = /define\((\[[^\]]*\]),/;20 var depMatches = test.match(depRE);21 var metadata;22 if (matches && matches[1]) {23 try {24 metadata = JSON.parse(matches[1]);25 } catch (e) {26 throw new Error('Error Parsing Metadata: ' + file + '\nInput: `' + matches[1] + '`');27 }28 }29 else {30 metadata = {};31 }32 var docs = null;33 if (docmatches && docmatches[1]) {34 docs = marked(docmatches[1].trim());35 }36 metadata.doc = docs;37 var deps = [];38 var matchedDeps;39 if (depMatches && depMatches[1]) {40 try {41 matchedDeps = JSON.parse(depMatches[1].replace(/'/g, '"'));42 } catch (e) {43 throw new Error('Couldn\'t parse dependencies for `' + file + '`:\n`' + depMatches[1] + '\n`');44 }45 matchedDeps.forEach(function(dep) {46 if (dep === 'Modernizr') {47 return;48 }49 deps.push(dep);50 });51 } else {52 throw new Error('Couldn\'t find the define for `' + file + '`');53 }54 metadata.deps = deps;55 var baseDir = __dirname.replace(/lib$/, '');56 metadata.path = './' + (start + '/' + file).replace(baseDir, '').replace(/\\/g, '/');57 metadata.amdPath = metadata.path.replace(/^\.\/feature\-detects/, 'test').replace(/\.js$/i, '');58 if (!metadata.name) {59 metadata.name = metadata.amdPath;60 }61 var pfs = [];62 if (metadata.polyfills && metadata.polyfills.length) {63 metadata.polyfills.forEach(function(polyname) {64 if (polyfills[polyname]) {65 pfs.push(polyfills[polyname]);66 }67 else {68 throw new Error(metadata.name + ': Polyfill not found in `' + file + '`: ' + polyname);69 }70 });71 }72 metadata.polyfills = pfs;73 if (!metadata.async) {74 metadata.async = false;75 }76 if (!metadata.notes) {77 metadata.notes = [];78 }79 if (!metadata.warnings) {80 metadata.warnings = [];81 }82 if (!metadata.caniuse) {83 metadata.caniuse = null;84 }85 if (!metadata.cssclass && metadata.property) {86 metadata.cssclass = metadata.property;87 } else {88 metadata.cssclass = null;89 }90 // Maybe catch a bug91 if (!metadata.doc && metadata.docs) {92 metadata.doc = metadata.docs;93 delete metadata.docs;94 }95 // If you want markdown parsed code minus the docs and metadata, this'll do it.96 // Off by default for now.97 // metadata.code = marked('```javascript\n' + test.replace(metaRE, '').replace(docRE, '') + '\n```');98 if (!metadata.tags) {99 metadata.tags = [];100 }101 if (!metadata.authors) {102 metadata.authors = [];103 }104 if (!metadata.knownBugs) {105 metadata.knownBugs = [];106 }107 tests.push(metadata);108 });109 });110 if (cb && typeof cb == 'function') {111 return cb(tests);112 }113 return tests;114}...

Full Screen

Full Screen

index.ts

Source:index.ts Github

copy

Full Screen

1import Statement from '../../../../models/Statement';2import { getBooleanMetadata } from './getBooleanMetadata';3import { getChoiceQuestionMetadata } from './getChoiceQuestionMetadata';4import { getDurationMetadata } from './getDurationMetadata';5import { getLikertMetadata } from './getLikertMetadata';6import { getMatchingQuestionsMetadata } from './getMatchingQuestionsMetadata';7import { getNumericQuestionMetadata } from './getNumericQuestionMetadata';8import { getSequencingMetadata } from './getSequencingMetadata';9export default (statement: Statement): { readonly [key: string]: any } => {10 const likertMetadata = getLikertMetadata(statement);11 const durationMetadata = getDurationMetadata(statement);12 const sequencingMetadata = getSequencingMetadata(statement);13 const choicesMetadata = getChoiceQuestionMetadata(statement);14 const matchingMetadata = getMatchingQuestionsMetadata(statement);15 const booleanMetadata = getBooleanMetadata(statement);16 const numericQuestionMetadata = getNumericQuestionMetadata(statement);17 return {18 ...durationMetadata,19 ...sequencingMetadata,20 ...numericQuestionMetadata,21 ...choicesMetadata,22 ...matchingMetadata,23 ...booleanMetadata,24 ...likertMetadata,25 };...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { metaData } from 'storybook-root';2import { metaData } from 'storybook-root';3import { metaData } from 'storybook-root';4import { metaData } from 'storybook-root';5import { metaData } from 'storybook-root';6import { metaData } from 'storybook-root';7import { metaData } from 'storybook-root';8import { metaData } from 'storybook-root';9import { metaData } from 'storybook-root';10import { metaData } from 'storybook-root';11import { metaData } from 'storybook-root';12import { metaData } from 'storybook-root';13import { metaData } from 'storybook-root';14import { metaData } from 'storybook-root';15import { metaData } from 'storybook-root';16import { metaData } from 'storybook-root';17import { metaData } from 'storybook-root';18import { metaData } from 'storybook-root';19import { metaData } from 'storybook-root';20import { metaData } from 'storybook-root';21import { metaData } from 'storybook-root';22import { metaData } from 'storybook-root';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { metaData } from 'storybook-root';2import { metaData } from 'storybook-root';3import { metaData } from 'storybook-root';4import { metaData } from 'storybook-root';5import { metaData } from 'storybook-root';6import { metaData } from 'storybook-root';7import { metaData } from 'storybook-root';8import { metaData } from 'storybook-root';9import { metaData } from 'storybook-root';10import { metaData } from 'storybook-root';11import { metaData } from 'storybook-root';12import { metaData } from 'storybook-root';13import { metaData } from 'storybook-root';14import { metaData } from 'storybook-root';

Full Screen

Using AI Code Generation

copy

Full Screen

1const { metaData } = require('@storybook-root');2const { name, version } = metaData();3const { metaData } = require('@storybook-root');4const { name, version } = metaData();5const { metaData } = require('@storybook-root');6const { name, version } = metaData();7const { metaData } = require('@storybook-root');8const { name, version } = metaData();9const { metaData } = require('@storybook-root');10const { name, version } = metaData();11const { metaData } = require('@storybook-root');12const { name, version } = metaData();13const { metaData } = require('@storybook-root');14const { name, version } = metaData();15const { metaData } = require('@storybook-root');16const { name, version } = metaData();17const { metaData } = require('@storybook-root');18const { name, version } = metaData();19const { metaData } = require('@storybook-root');20const { name, version } = metaData();21const { metaData } = require('@storybook-root');22const { name, version } = metaData();23const { metaData } = require('@storybook-root');24const { name, version } = metaData();25const { metaData } = require('@storybook-root');26const { name, version } = metaData();27const { metaData } = require('@storybook-root');28const { name, version } = metaData();29const { metaData } = require('@storybook-root');30const { name, version } = metaData();31const { metaData } = require('@

Full Screen

Using AI Code Generation

copy

Full Screen

1import { metaData } from 'storybook-root';2console.log(metaData);3{4 "scripts": {5 },6}7import { metaData } from 'storybook-root';8const path = metaData.main;9const component = await import(`../../${path}`);10const req = require.context('../../src', true, /\.js$/);11const component = req('./component.js');12const path = require('path');13const component = await import(`../../${path.resolve(__dirname, metaData.main)}`);14import { metaData } from 'storybook-root';15const path = metaData.main;16const component = await import(`../../${path}`);17const req = require.context('../../src', true, /\.js$/);18const component = req('./component.js');19const path = require('path');20const component = await import(`../../${path.resolve(__dirname, metaData.main)}`);

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful