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