Clarify types for rename_identifiers and get_new_name

pull/8553/head
Nguyen Tran 3 years ago
parent 43aba2b958
commit e50a4a25b2

@ -25,7 +25,7 @@ import TemplateScope from './nodes/shared/TemplateScope';
import fuzzymatch from '../utils/fuzzymatch';
import get_object from './utils/get_object';
import Slot from './nodes/Slot';
import { Node, ImportDeclaration, ExportNamedDeclaration, Identifier, ExpressionStatement, AssignmentExpression, Literal, Property, RestElement, ExportDefaultDeclaration, ExportAllDeclaration, FunctionDeclaration, FunctionExpression } from 'estree';
import { Node, ImportDeclaration, ExportNamedDeclaration, Identifier, ExpressionStatement, AssignmentExpression, Literal, Property, RestElement, ExportDefaultDeclaration, ExportAllDeclaration, FunctionDeclaration, FunctionExpression, Pattern, Expression } from 'estree';
import add_to_set from './utils/add_to_set';
import check_graph_for_cycles from './utils/check_graph_for_cycles';
import { print, b } from 'code-red';
@ -1034,7 +1034,7 @@ export default class Component {
const inserts = [];
const props = [];
function add_new_props(exported, local, default_value) {
function add_new_props(exported: Identifier, local: Pattern, default_value: Expression) {
props.push({
type: 'Property',
method: false,
@ -1064,7 +1064,7 @@ export default class Component {
for (let index = 0; index < node.declarations.length; index++) {
const declarator = node.declarations[index];
if (declarator.id.type !== 'Identifier') {
function get_new_name(local) {
function get_new_name(local: Identifier): Identifier {
const variable = component.var_lookup.get(local.name);
if (variable.subscribable) {
inserts.push(get_insert(variable));
@ -1078,7 +1078,7 @@ export default class Component {
return local;
}
function rename_identifiers(param: Node) {
function rename_identifiers(param: Pattern) {
switch (param.type) {
case 'ObjectPattern': {
const handle_prop = (prop: Property | RestElement) => {
@ -1087,7 +1087,7 @@ export default class Component {
} else if (prop.value.type === 'Identifier') {
prop.value = get_new_name(prop.value);
} else {
rename_identifiers(prop.value);
rename_identifiers(prop.value as Pattern);
}
};
@ -1095,7 +1095,7 @@ export default class Component {
break;
}
case 'ArrayPattern': {
const handle_element = (element: Node, index: number, array: Node[]) => {
const handle_element = (element: Pattern | null, index: number, array: Array<Pattern | null>) => {
if (element) {
if (element.type === 'Identifier') {
array[index] = get_new_name(element);

Loading…
Cancel
Save