Include typeAnnotation inside of node location (#2039)

We should remove this hack once https://github.com/eslint/typescript-eslint-parser/issues/314 lands

Fixes #1946
master
Christopher Chedeau 2017-06-07 15:05:46 -07:00 committed by GitHub
parent 42b0368e3d
commit 1edb1f261b
3 changed files with 125 additions and 6 deletions

View File

@ -230,15 +230,19 @@ function locStart(node) {
}
function locEnd(node) {
let loc;
if (node.range) {
return node.range[1];
loc = node.range[1];
} else if (typeof node.end === "number") {
loc = node.end;
} else if (node.source) {
loc = lineColumnToIndex(node.source.end, node.source.input.css);
}
if (typeof node.end === "number") {
return node.end;
}
if (node.source) {
return lineColumnToIndex(node.source.end, node.source.input.css);
if (node.typeAnnotation) {
return Math.max(loc, locEnd(node.typeAnnotation));
}
return loc;
}
// Super inefficient, needs to be cached.

View File

@ -44,6 +44,86 @@ var example2 = (
`;
exports[`location.ts 1`] = `
function x({
x,
y,
}: {
// Hello world.
x: string,
// Yoyo.
y: string,
}) {}
export interface ApplicationEventData {
registerBroadcastReceiver(onReceiveCallback: (
context: any /* android.content.Context */,
intent: any /* android.content.Intent */
) => void): void;
}
export type WrappedFormUtils = {
getFieldDecorator(id: string, options?: {
/** 子节点的值的属性,如 Checkbox 的是 'checked' */
valuePropName?: string;
/** 子节点的初始值,类型、可选值均由子节点决定 */
initialValue?: any;
/** 收集子节点的值的时机 */
trigger?: string;
/** 可以把 onChange 的参数转化为控件的值,例如 DatePicker 可设为:(date, dateString) => dateString */
getValueFromEvent?: (...args: any[]) => any;
/** 校验子节点值的时机 */
validateTrigger?: string | string[];
/** 校验规则,参见 [async-validator](https://github.com/yiminghe/async-validator) */
rules?: ValidationRule[];
/** 是否和其他控件互斥,特别用于 Radio 单选控件 */
exclusive?: boolean;
}): (node: React.ReactNode) => React.ReactNode;
};
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function x({
x,
y
}: {
// Hello world.
x: string;
// Yoyo.
y: string;
}) {}
export interface ApplicationEventData {
registerBroadcastReceiver(
onReceiveCallback: (
context: any /* android.content.Context */,
intent: any /* android.content.Intent */
) => void
): void;
}
export type WrappedFormUtils = {
getFieldDecorator(
id: string,
options?: {
/** 子节点的值的属性,如 Checkbox 的是 'checked' */
valuePropName?: string;
/** 子节点的初始值,类型、可选值均由子节点决定 */
initialValue?: any;
/** 收集子节点的值的时机 */
trigger?: string;
/** 可以把 onChange 的参数转化为控件的值,例如 DatePicker 可设为:(date, dateString) => dateString */
getValueFromEvent?: (...args: any[]) => any;
/** 校验子节点值的时机 */
validateTrigger?: string | string[];
/** 校验规则,参见 [async-validator](https://github.com/yiminghe/async-validator) */
rules?: ValidationRule[];
/** 是否和其他控件互斥,特别用于 Radio 单选控件 */
exclusive?: boolean;
}
): (node: React.ReactNode) => React.ReactNode;
};
`;
exports[`types.ts 1`] = `
(() => {
// swallow error and fallback to using directory as path

View File

@ -0,0 +1,35 @@
function x({
x,
y,
}: {
// Hello world.
x: string,
// Yoyo.
y: string,
}) {}
export interface ApplicationEventData {
registerBroadcastReceiver(onReceiveCallback: (
context: any /* android.content.Context */,
intent: any /* android.content.Intent */
) => void): void;
}
export type WrappedFormUtils = {
getFieldDecorator(id: string, options?: {
/** 子节点的值的属性,如 Checkbox 的是 'checked' */
valuePropName?: string;
/** 子节点的初始值,类型、可选值均由子节点决定 */
initialValue?: any;
/** 收集子节点的值的时机 */
trigger?: string;
/** 可以把 onChange 的参数转化为控件的值,例如 DatePicker 可设为:(date, dateString) => dateString */
getValueFromEvent?: (...args: any[]) => any;
/** 校验子节点值的时机 */
validateTrigger?: string | string[];
/** 校验规则,参见 [async-validator](https://github.com/yiminghe/async-validator) */
rules?: ValidationRule[];
/** 是否和其他控件互斥,特别用于 Radio 单选控件 */
exclusive?: boolean;
}): (node: React.ReactNode) => React.ReactNode;
};