|
1 | 1 | import type MagicString from 'magic-string'; |
2 | 2 | import type { RenderOptions } from '../../utils/renderHelpers'; |
| 3 | +import { CallOptions } from '../CallOptions'; |
| 4 | +import { HasEffectsContext } from '../ExecutionContext'; |
3 | 5 | import type { ObjectPath } from '../utils/PathTracker'; |
| 6 | +import { |
| 7 | + getMemberReturnExpressionWhenCalled, |
| 8 | + hasMemberEffectWhenCalled, |
| 9 | + literalStringMembers |
| 10 | +} from '../values'; |
4 | 11 | import type * as NodeType from './NodeType'; |
5 | 12 | import type TemplateElement from './TemplateElement'; |
6 | | -import { type LiteralValueOrUnknown, UnknownValue } from './shared/Expression'; |
| 13 | +import { |
| 14 | + ExpressionEntity, |
| 15 | + type LiteralValueOrUnknown, |
| 16 | + UNKNOWN_EXPRESSION, |
| 17 | + UnknownValue |
| 18 | +} from './shared/Expression'; |
7 | 19 | import { type ExpressionNode, NodeBase } from './shared/Node'; |
8 | 20 |
|
9 | 21 | export default class TemplateLiteral extends NodeBase { |
10 | 22 | declare expressions: ExpressionNode[]; |
11 | 23 | declare quasis: TemplateElement[]; |
12 | 24 | declare type: NodeType.tTemplateLiteral; |
13 | 25 |
|
| 26 | + deoptimizeThisOnEventAtPath(): void {} |
| 27 | + |
14 | 28 | getLiteralValueAtPath(path: ObjectPath): LiteralValueOrUnknown { |
15 | 29 | if (path.length > 0 || this.quasis.length !== 1) { |
16 | 30 | return UnknownValue; |
17 | 31 | } |
18 | 32 | return this.quasis[0].value.cooked; |
19 | 33 | } |
20 | 34 |
|
| 35 | + getReturnExpressionWhenCalledAtPath(path: ObjectPath): ExpressionEntity { |
| 36 | + if (path.length !== 1) { |
| 37 | + return UNKNOWN_EXPRESSION; |
| 38 | + } |
| 39 | + return getMemberReturnExpressionWhenCalled(literalStringMembers, path[0]); |
| 40 | + } |
| 41 | + |
| 42 | + hasEffectsWhenAccessedAtPath(path: ObjectPath): boolean { |
| 43 | + return path.length > 1; |
| 44 | + } |
| 45 | + |
| 46 | + hasEffectsWhenCalledAtPath( |
| 47 | + path: ObjectPath, |
| 48 | + callOptions: CallOptions, |
| 49 | + context: HasEffectsContext |
| 50 | + ): boolean { |
| 51 | + if (path.length === 1) { |
| 52 | + return hasMemberEffectWhenCalled(literalStringMembers, path[0], callOptions, context); |
| 53 | + } |
| 54 | + return true; |
| 55 | + } |
| 56 | + |
21 | 57 | render(code: MagicString, options: RenderOptions): void { |
22 | 58 | (code.indentExclusionRanges as [number, number][]).push([this.start, this.end]); |
23 | 59 | super.render(code, options); |
|
0 commit comments