UNPKG

sucrase

Version:

Super-fast alternative to Babel for when you can target modern JS runtimes

34 lines (33 loc) 1.41 kB
import { Transformer } from './Transformer'; import { RootTransformer } from '../index'; import TokenProcessor from '../TokenProcessor'; import IdentifierReplacer from './IdentifierReplacer'; /** * Implementation of babel-plugin-transform-react-display-name, which adds a * display name to usages of React.createClass and createReactClass. * * This implementation has the following limitations compared with the * - It does not handle `export default React.createClass`, using the filename, * since Sucrase currently does not know the name of the current file. */ export default class ReactDisplayNameTransformer implements Transformer { readonly rootTransformer: RootTransformer; readonly tokens: TokenProcessor; readonly identifierReplacer: IdentifierReplacer; constructor(rootTransformer: RootTransformer, tokens: TokenProcessor, identifierReplacer: IdentifierReplacer); preprocess(): void; process(): boolean; /** * This is called with the token position at the open-paren. */ private tryProcessCreateClassCall(startIndex); private findDisplayName(startIndex); /** * We only want to add a display name when this is a function call containing * one argument, which is an object literal without `displayName` as an * existing key. */ private classNeedsDisplayName(); getPrefixCode(): string; getSuffixCode(): string; }