This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function PropertyDecorator (propertyOptions) { | |
| // Modify the property in some way: | |
| return propertyDescriptor; | |
| } | |
| function MethodDecorator (methodOptions) { | |
| // Modify the method in some way: | |
| return methodDescriptor; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function PropertyDecorator (property) { | |
| // Modify the property in some way: | |
| return property; | |
| } | |
| function MethodDecorator (method) { | |
| // Modify the method in some way: | |
| return method; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { createPrinter, transform, SourceFile} from 'typescript'; | |
| import { transformer } from './transformer'; | |
| function transformFile (file: SourceFile): string { | |
| const result = transform(file, [transformer(file)]); | |
| const [transformed] = result.transformed; | |
| const printer = createPrinter(); | |
| return printer.printFile(transformed as SourceFile); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type Freezable = { | |
| unfreezable?: never; // Need to make the unfreezable property optional | |
| }; | |
| type Frozen<T extends Freezable = Freezable> = T & { | |
| frozen: true; | |
| }; | |
| type Thawed<T> = T extends Frozen<infer R> | |
| ? R |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (navigator.getBattery) { | |
| navigator.getBattery().then((battery) => { | |
| if (battery && battery.level < 0.2) { | |
| let disableAnimations = document.createElement('style'); | |
| disableAnimations.type = 'text/css'; | |
| disableAnimations.innerHTML = ` | |
| * { | |
| transition-property: none !important; | |
| animation: none !important; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { AbstractWalker } from 'tslint'; | |
| import { forEachChild, Node, SourceFile, SyntaxKind } from 'typescript'; | |
| class NoFDescribeOrFItWalker extends AbstractWalker { | |
| public walk (sourceFile: SourceFile) { | |
| const walkNode = (node: Node): void => { | |
| if (node.kind === SyntaxKind.CallExpression) { | |
| if (node.expression.kind === SyntaxKind.Identifier) { | |
| // possible rule match! | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Check it out here: | |
| https://www.typescriptlang.org/play?ts=4.1.0-dev.20201001#code/C4TwDgpgBAcgrgWwEYQE4GcoF4oHIAMuUAPngIxGm4BMleAzHbgCxMCsTAbEwOxMAcTAJy4A3AChQkWAHsAdgC00M7FACiADwDGAGzgATCAB54yNOgA0eQgD4Jk8NACaEAIapVAAwAkAb1MoGAC+fgHmIf6IgegRYcGeElLQALLywAAWmDie+KHySqgyQZ4k5ISluGQUFWS0iY5QACKuIFlQPr4ETNVUtLH5ysUV9OVU9BT2SVAAEjJwGF65kWbxpZ5koVHhJb2jeNQ9+7QV1IwnrPXSCvIQs-NtMAOFa0uPioM7Zd2HlbQO0skAJZyODACBtDpdGpMY5jJisCocWJbeKXaAAZQgWnk+jaQJBYPQaKgQJ0OkB6CxOIhmxWMVp0WRdOKkwa1zkEAACqgIAAzQEaVS4ADUTAAtGJxP9oM0wZz3JS1KhCqgjMlwehXABzaAQDRguS4qDoYCoYFamyqXxQNAqgBcJI12ugQVZ0llEAAKoCEMZxFAA1BPTb9RBDZgTWa5FrxJacP7A8G9QajR1gby0E1XGDvb6ggo-OnM+yIEMAPxQBOBwPyjAQD25iAlowNn0QKwly12qtBkMpzBpuQZjwe8s96u1ymt32PZseruV6seycQJUqoyeacQB0ASTkADdXOT9Fmc22HX5PcU7FKpiut82e1v0aa+2GjZHzRYeyWXx5k++Eaml+PYrvoW6qPe2Zem2s43C20GNn+NjfhOCoQPoJaQehza-qaNixthdbgYhbZvuGp4wb6f5QGW441uhmE3ORRp4R4dHVpxgYdGBW75n4YElkM3ZcQGgnMSJDHEVubrQFBZ4zjIj5LqRilsSxQFRjGcaLoGW5wRyNEARRg7DpRQSeoWQ6Zo25a6Vx8lUcYHpWI2XZPqpEAGRARmhiZVlmaOJQcaJjkIWCC4eXK6FrjIqqeI5jb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Dependencies: | |
| import { tsquery } from '@phenomnomnominal/tsquery'; | |
| import { tstemplate } from '@phenomnomnominal/tstemplate'; | |
| import { createIdentifier, createLiteral, createToken, SyntaxKind, visitEachChild, visitNode } from 'typescript'; | |
| import { Node, PropertyDeclaration, SourceFile, TransformationContext, Transformer, TransformerFactory } from 'typescript'; | |
| // Constants: | |
| const CAST_PROPERTIES_QUERY = `PropertyDeclaration:has(Decorator:has(Identifier[name="Value"]))`; | |
| const RESULT_QUERY = 'PropertyDeclaration, GetAccessor, SetAccessor'; | |
| const OTHER_DECORATORS_QUERY = `Decorator:has(Decorator > CallExpression[expression.name!="Value"])`; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import callsite from 'callsite'; | |
| import { releaseProxy, wrap } from 'comlink'; | |
| import nodeEndpoint from 'comlink/dist/umd/node-adapter'; | |
| import path from 'path'; | |
| import { Worker } from 'worker_threads'; | |
| const WORKER_PATH = path.resolve(__dirname, './worker.js'); | |
| export function workerRequire(id) { | |
| const [, call] = callsite(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // BEFORE: | |
| const { somethingCPUIntensive } = require('./cpu-intensive'); | |
| somethingCPUIntensive(); // run synchronously blocking the main thread | |
| // AFTER: | |
| const { somethingCPUIntensive } = workerRequire('./cpu-intensive'); | |
| await somethingCPUIntensive(); // run asynchronously in a worker thread |
NewerOlder