|
|
@ -13,31 +13,25 @@ const DIRECTIVES = {
|
|
|
|
EventHandler: {
|
|
|
|
EventHandler: {
|
|
|
|
names: ['on'],
|
|
|
|
names: ['on'],
|
|
|
|
allowedExpressionTypes: ['CallExpression'],
|
|
|
|
allowedExpressionTypes: ['CallExpression'],
|
|
|
|
|
|
|
|
attribute(start, end, type, name, expression) {
|
|
|
|
|
|
|
|
return { start, end, type, name, expression };
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
Binding: {
|
|
|
|
Binding: {
|
|
|
|
names: [ '', 'bind' ],
|
|
|
|
names: ['bind'],
|
|
|
|
allowedExpressionTypes: ['Identifier', 'MemberExpression'],
|
|
|
|
allowedExpressionTypes: ['Identifier', 'MemberExpression'],
|
|
|
|
attribute(start, end, type, name, expression, directiveName) {
|
|
|
|
attribute(start, end, type, name, expression) {
|
|
|
|
let value;
|
|
|
|
return {
|
|
|
|
|
|
|
|
start, end, type, name,
|
|
|
|
// :foo is shorthand for foo='{{foo}}'
|
|
|
|
value: expression || {
|
|
|
|
if (!directiveName) {
|
|
|
|
|
|
|
|
const valueStart = start + 1;
|
|
|
|
|
|
|
|
const valueEnd = start + name.length;
|
|
|
|
|
|
|
|
type = 'Attribute';
|
|
|
|
|
|
|
|
value = getShorthandValue(start + 1, name);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
value = expression || {
|
|
|
|
|
|
|
|
type: 'Identifier',
|
|
|
|
type: 'Identifier',
|
|
|
|
start: start + 5,
|
|
|
|
start: start + 5,
|
|
|
|
end,
|
|
|
|
end,
|
|
|
|
name,
|
|
|
|
name,
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return { start, end, type, name, value };
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
Transition: {
|
|
|
|
Transition: {
|
|
|
@ -48,9 +42,9 @@ const DIRECTIVES = {
|
|
|
|
start, end, type, name, expression,
|
|
|
|
start, end, type, name, expression,
|
|
|
|
intro: directiveName === 'in' || directiveName === 'transition',
|
|
|
|
intro: directiveName === 'in' || directiveName === 'transition',
|
|
|
|
outro: directiveName === 'out' || directiveName === 'transition',
|
|
|
|
outro: directiveName === 'out' || directiveName === 'transition',
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -83,7 +77,7 @@ function readExpression(parser: Parser, start: number, quoteMark: string|null) {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
str += char;
|
|
|
|
str += char;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (/[\s\r\n\/>]/.test(char)) {
|
|
|
|
} else if (/[\s\/>]/.test(char)) {
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
str += char;
|
|
|
|
str += char;
|
|
|
@ -109,6 +103,17 @@ export function readDirective(
|
|
|
|
const [directiveName, name] = attrName.split(':');
|
|
|
|
const [directiveName, name] = attrName.split(':');
|
|
|
|
if (name === undefined) return; // No colon in the name
|
|
|
|
if (name === undefined) return; // No colon in the name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (directiveName === '') {
|
|
|
|
|
|
|
|
// not a directive — :foo is short for foo={{foo}}
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
start: start,
|
|
|
|
|
|
|
|
end: start + name.length + 1,
|
|
|
|
|
|
|
|
type: 'Attribute',
|
|
|
|
|
|
|
|
name,
|
|
|
|
|
|
|
|
value: getShorthandValue(start + 1, name)
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const type = lookupByName[directiveName];
|
|
|
|
const type = lookupByName[directiveName];
|
|
|
|
if (!type) return; // not a registered directive
|
|
|
|
if (!type) return; // not a registered directive
|
|
|
|
|
|
|
|
|
|
|
@ -137,17 +142,7 @@ export function readDirective(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (directive.attribute) {
|
|
|
|
|
|
|
|
return directive.attribute(start, parser.index, type, name, expression, directiveName);
|
|
|
|
return directive.attribute(start, parser.index, type, name, expression, directiveName);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
start,
|
|
|
|
|
|
|
|
end: parser.index,
|
|
|
|
|
|
|
|
type: type,
|
|
|
|
|
|
|
|
name,
|
|
|
|
|
|
|
|
expression,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|