From 6e8a3830c29b6f29c06d2de091240e1a880f21aa Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 1 Oct 2018 09:16:21 -0700 Subject: [PATCH] Fix the lookbehind for multiline arrow to include return keyword Fixes #672 --- TypeScript.YAML-tmLanguage | 2 +- TypeScript.tmLanguage | 2 +- TypeScriptReact.tmLanguage | 2 +- tests/baselines/Issue672.baseline.txt | 374 ++++++++++++++++++++++++++ tests/cases/Issue672.ts | 14 + 5 files changed, 391 insertions(+), 3 deletions(-) create mode 100644 tests/baselines/Issue672.baseline.txt create mode 100644 tests/cases/Issue672.ts diff --git a/TypeScript.YAML-tmLanguage b/TypeScript.YAML-tmLanguage index 55abe271..2cdd33d4 100644 --- a/TypeScript.YAML-tmLanguage +++ b/TypeScript.YAML-tmLanguage @@ -57,7 +57,7 @@ variables: inlineComment: \/\*([^\*]|(\*[^\/]))*\*\/ startOfDeclaration: '{{startOfIdentifier}}(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?' lookBehindOfPossiblyMultilineArrowWithDestructuring: (?<=[(=,]) - lookBehindOfPossiblyMultilineArrow: (?<=[(=,]|=>) + lookBehindOfPossiblyMultilineArrow: (?<=[(=,]|=>|{{lookBehindReturn}}) lookBehindOfObjectMemberPossiblyMultilineArrow: (?<=:) # Identifier start | matching braces | matching parenthesis | matching square brackets typeParamersStart: ([_$[:alpha:]]|{{matchingBraces}}|{{matchingParenthesis}}|{{matchingBrackets}}) diff --git a/TypeScript.tmLanguage b/TypeScript.tmLanguage index 29f15ebe..8509d1d0 100644 --- a/TypeScript.tmLanguage +++ b/TypeScript.tmLanguage @@ -4538,7 +4538,7 @@ begin - (?<=[(=,]|=>)\s*(async)?(?=\s*((((<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*>\s*))?\()|(<))\s*$) + (?<=[(=,]|=>|^return|[^\._$[:alnum:]]return)\s*(async)?(?=\s*((((<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*>\s*))?\()|(<))\s*$) beginCaptures 1 diff --git a/TypeScriptReact.tmLanguage b/TypeScriptReact.tmLanguage index 0ede0f41..b6436e80 100644 --- a/TypeScriptReact.tmLanguage +++ b/TypeScriptReact.tmLanguage @@ -4542,7 +4542,7 @@ begin - (?<=[(=,]|=>)\s*(async)?(?=\s*((((<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*>\s*))?\()|(<))\s*$) + (?<=[(=,]|=>|^return|[^\._$[:alnum:]]return)\s*(async)?(?=\s*((((<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*>\s*))?\()|(<))\s*$) beginCaptures 1 diff --git a/tests/baselines/Issue672.baseline.txt b/tests/baselines/Issue672.baseline.txt new file mode 100644 index 00000000..3f245cbd --- /dev/null +++ b/tests/baselines/Issue672.baseline.txt @@ -0,0 +1,374 @@ +original file +----------------------------------- +export function computed(...watchedProps: K[]) { + if (watchedProps.length < 1) throw new Error('@computed() decorator must have at least one property argument'); + + return >( + _target: T, + _prop: string | symbol, + desc: TypedPropertyDescriptor + ) => { + if (!desc.get) throw new Error('The `@computed()` decorator must be used on `get` method.'); + if (desc.set) throw new Error('The `@computed()` decorator cannot be used with `set` method.'); + if (desc.value) throw new Error('The `@computed()` decorator cannot be used with a regular function.'); + // .... + }; +} +----------------------------------- + +Grammar: TypeScript.tmLanguage +----------------------------------- +>export function computed(...watchedProps: K[]) { + ^^^^^^ + source.ts meta.function.ts keyword.control.export.ts + ^ + source.ts meta.function.ts + ^^^^^^^^ + source.ts meta.function.ts storage.type.function.ts + ^ + source.ts meta.function.ts + ^^^^^^^^ + source.ts meta.function.ts meta.definition.function.ts entity.name.function.ts + ^ + source.ts meta.function.ts meta.type.parameters.ts punctuation.definition.typeparameters.begin.ts + ^ + source.ts meta.function.ts meta.type.parameters.ts entity.name.type.ts + ^ + source.ts meta.function.ts meta.type.parameters.ts + ^^^^^^^ + source.ts meta.function.ts meta.type.parameters.ts storage.modifier.ts + ^ + source.ts meta.function.ts meta.type.parameters.ts + ^^^^^^ + source.ts meta.function.ts meta.type.parameters.ts support.type.primitive.ts + ^ + source.ts meta.function.ts meta.type.parameters.ts + ^ + source.ts meta.function.ts meta.type.parameters.ts keyword.operator.type.ts + ^ + source.ts meta.function.ts meta.type.parameters.ts + ^^^^^^ + source.ts meta.function.ts meta.type.parameters.ts support.type.primitive.ts + ^ + source.ts meta.function.ts meta.type.parameters.ts punctuation.definition.typeparameters.end.ts + ^ + source.ts meta.function.ts meta.parameters.ts punctuation.definition.parameters.begin.ts + ^^^ + source.ts meta.function.ts meta.parameters.ts keyword.operator.rest.ts + ^^^^^^^^^^^^ + source.ts meta.function.ts meta.parameters.ts variable.parameter.ts + ^ + source.ts meta.function.ts meta.parameters.ts meta.type.annotation.ts keyword.operator.type.annotation.ts + ^ + source.ts meta.function.ts meta.parameters.ts meta.type.annotation.ts + ^ + source.ts meta.function.ts meta.parameters.ts meta.type.annotation.ts entity.name.type.ts + ^ + source.ts meta.function.ts meta.parameters.ts meta.type.annotation.ts meta.type.tuple.ts meta.brace.square.ts + ^ + source.ts meta.function.ts meta.parameters.ts meta.type.annotation.ts meta.type.tuple.ts meta.brace.square.ts + ^ + source.ts meta.function.ts meta.parameters.ts punctuation.definition.parameters.end.ts + ^ + source.ts meta.function.ts + ^ + source.ts meta.function.ts meta.block.ts punctuation.definition.block.ts +> if (watchedProps.length < 1) throw new Error('@computed() decorator must have at least one property argument'); + ^^ + source.ts meta.function.ts meta.block.ts + ^^ + source.ts meta.function.ts meta.block.ts keyword.control.conditional.ts + ^ + source.ts meta.function.ts meta.block.ts + ^ + source.ts meta.function.ts meta.block.ts meta.brace.round.ts + ^^^^^^^^^^^^ + source.ts meta.function.ts meta.block.ts variable.other.object.ts + ^ + source.ts meta.function.ts meta.block.ts punctuation.accessor.ts + ^^^^^^ + source.ts meta.function.ts meta.block.ts support.variable.property.ts + ^ + source.ts meta.function.ts meta.block.ts + ^ + source.ts meta.function.ts meta.block.ts keyword.operator.relational.ts + ^ + source.ts meta.function.ts meta.block.ts + ^ + source.ts meta.function.ts meta.block.ts constant.numeric.decimal.ts + ^ + source.ts meta.function.ts meta.block.ts meta.brace.round.ts + ^ + source.ts meta.function.ts meta.block.ts + ^^^^^ + source.ts meta.function.ts meta.block.ts keyword.control.trycatch.ts + ^ + source.ts meta.function.ts meta.block.ts + ^^^ + source.ts meta.function.ts meta.block.ts new.expr.ts keyword.operator.new.ts + ^ + source.ts meta.function.ts meta.block.ts new.expr.ts + ^^^^^ + source.ts meta.function.ts meta.block.ts new.expr.ts entity.name.type.ts + ^ + source.ts meta.function.ts meta.block.ts new.expr.ts meta.brace.round.ts + ^ + source.ts meta.function.ts meta.block.ts new.expr.ts string.quoted.single.ts punctuation.definition.string.begin.ts + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + source.ts meta.function.ts meta.block.ts new.expr.ts string.quoted.single.ts + ^ + source.ts meta.function.ts meta.block.ts new.expr.ts string.quoted.single.ts punctuation.definition.string.end.ts + ^ + source.ts meta.function.ts meta.block.ts new.expr.ts meta.brace.round.ts + ^ + source.ts meta.function.ts meta.block.ts punctuation.terminator.statement.ts +> + ^ + source.ts meta.function.ts meta.block.ts +> return >( + ^^ + source.ts meta.function.ts meta.block.ts + ^^^^^^ + source.ts meta.function.ts meta.block.ts keyword.control.flow.ts + ^ + source.ts meta.function.ts meta.block.ts + ^ + source.ts meta.function.ts meta.block.ts meta.type.parameters.ts punctuation.definition.typeparameters.begin.ts + ^ + source.ts meta.function.ts meta.block.ts meta.type.parameters.ts entity.name.type.ts + ^ + source.ts meta.function.ts meta.block.ts meta.type.parameters.ts punctuation.separator.comma.ts + ^ + source.ts meta.function.ts meta.block.ts meta.type.parameters.ts + ^ + source.ts meta.function.ts meta.block.ts meta.type.parameters.ts entity.name.type.ts + ^ + source.ts meta.function.ts meta.block.ts meta.type.parameters.ts + ^^^^^^^ + source.ts meta.function.ts meta.block.ts meta.type.parameters.ts storage.modifier.ts + ^ + source.ts meta.function.ts meta.block.ts meta.type.parameters.ts + ^^^^^^ + source.ts meta.function.ts meta.block.ts meta.type.parameters.ts entity.name.type.ts + ^ + source.ts meta.function.ts meta.block.ts meta.type.parameters.ts meta.type.parameters.ts punctuation.definition.typeparameters.begin.ts + ^ + source.ts meta.function.ts meta.block.ts meta.type.parameters.ts meta.type.parameters.ts entity.name.type.ts + ^ + source.ts meta.function.ts meta.block.ts meta.type.parameters.ts meta.type.parameters.ts punctuation.separator.comma.ts + ^ + source.ts meta.function.ts meta.block.ts meta.type.parameters.ts meta.type.parameters.ts + ^^^ + source.ts meta.function.ts meta.block.ts meta.type.parameters.ts meta.type.parameters.ts support.type.primitive.ts + ^ + source.ts meta.function.ts meta.block.ts meta.type.parameters.ts meta.type.parameters.ts punctuation.definition.typeparameters.end.ts + ^ + source.ts meta.function.ts meta.block.ts meta.type.parameters.ts punctuation.definition.typeparameters.end.ts + ^ + source.ts meta.function.ts meta.block.ts meta.brace.round.ts +> _target: T, + ^^^^ + source.ts meta.function.ts meta.block.ts + ^^^^^^^ + source.ts meta.function.ts meta.block.ts variable.parameter.ts + ^ + source.ts meta.function.ts meta.block.ts meta.type.annotation.ts keyword.operator.type.annotation.ts + ^ + source.ts meta.function.ts meta.block.ts meta.type.annotation.ts + ^ + source.ts meta.function.ts meta.block.ts meta.type.annotation.ts entity.name.type.ts + ^ + source.ts meta.function.ts meta.block.ts punctuation.separator.parameter.ts +> _prop: string | symbol, + ^^^^ + source.ts meta.function.ts meta.block.ts + ^^^^^ + source.ts meta.function.ts meta.block.ts variable.parameter.ts + ^ + source.ts meta.function.ts meta.block.ts meta.type.annotation.ts keyword.operator.type.annotation.ts + ^ + source.ts meta.function.ts meta.block.ts meta.type.annotation.ts + ^^^^^^ + source.ts meta.function.ts meta.block.ts meta.type.annotation.ts support.type.primitive.ts + ^ + source.ts meta.function.ts meta.block.ts meta.type.annotation.ts + ^ + source.ts meta.function.ts meta.block.ts meta.type.annotation.ts keyword.operator.type.ts + ^ + source.ts meta.function.ts meta.block.ts meta.type.annotation.ts + ^^^^^^ + source.ts meta.function.ts meta.block.ts meta.type.annotation.ts support.type.primitive.ts + ^ + source.ts meta.function.ts meta.block.ts punctuation.separator.parameter.ts +> desc: TypedPropertyDescriptor + ^^^^ + source.ts meta.function.ts meta.block.ts + ^^^^ + source.ts meta.function.ts meta.block.ts variable.parameter.ts + ^ + source.ts meta.function.ts meta.block.ts meta.type.annotation.ts keyword.operator.type.annotation.ts + ^ + source.ts meta.function.ts meta.block.ts meta.type.annotation.ts + ^^^^^^^^^^^^^^^^^^^^^^^ + source.ts meta.function.ts meta.block.ts meta.type.annotation.ts entity.name.type.ts + ^ + source.ts meta.function.ts meta.block.ts meta.type.annotation.ts meta.type.parameters.ts punctuation.definition.typeparameters.begin.ts + ^ + source.ts meta.function.ts meta.block.ts meta.type.annotation.ts meta.type.parameters.ts entity.name.type.ts + ^ + source.ts meta.function.ts meta.block.ts meta.type.annotation.ts meta.type.parameters.ts punctuation.definition.typeparameters.end.ts +> ) => { + ^^ + source.ts meta.function.ts meta.block.ts + ^ + source.ts meta.function.ts meta.block.ts meta.brace.round.ts + ^ + source.ts meta.function.ts meta.block.ts + ^^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts storage.type.function.arrow.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts punctuation.definition.block.ts +> if (!desc.get) throw new Error('The `@computed()` decorator must be used on `get` method.'); + ^^^^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts + ^^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts keyword.control.conditional.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts meta.brace.round.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts keyword.operator.logical.ts + ^^^^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts variable.other.object.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts punctuation.accessor.ts + ^^^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts variable.other.property.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts meta.brace.round.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts + ^^^^^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts keyword.control.trycatch.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts + ^^^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts new.expr.ts keyword.operator.new.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts new.expr.ts + ^^^^^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts new.expr.ts entity.name.type.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts new.expr.ts meta.brace.round.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts new.expr.ts string.quoted.single.ts punctuation.definition.string.begin.ts + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts new.expr.ts string.quoted.single.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts new.expr.ts string.quoted.single.ts punctuation.definition.string.end.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts new.expr.ts meta.brace.round.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts punctuation.terminator.statement.ts +> if (desc.set) throw new Error('The `@computed()` decorator cannot be used with `set` method.'); + ^^^^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts + ^^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts keyword.control.conditional.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts meta.brace.round.ts + ^^^^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts variable.other.object.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts punctuation.accessor.ts + ^^^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts variable.other.property.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts meta.brace.round.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts + ^^^^^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts keyword.control.trycatch.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts + ^^^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts new.expr.ts keyword.operator.new.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts new.expr.ts + ^^^^^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts new.expr.ts entity.name.type.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts new.expr.ts meta.brace.round.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts new.expr.ts string.quoted.single.ts punctuation.definition.string.begin.ts + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts new.expr.ts string.quoted.single.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts new.expr.ts string.quoted.single.ts punctuation.definition.string.end.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts new.expr.ts meta.brace.round.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts punctuation.terminator.statement.ts +> if (desc.value) throw new Error('The `@computed()` decorator cannot be used with a regular function.'); + ^^^^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts + ^^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts keyword.control.conditional.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts meta.brace.round.ts + ^^^^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts variable.other.object.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts punctuation.accessor.ts + ^^^^^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts support.variable.property.dom.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts meta.brace.round.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts + ^^^^^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts keyword.control.trycatch.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts + ^^^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts new.expr.ts keyword.operator.new.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts new.expr.ts + ^^^^^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts new.expr.ts entity.name.type.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts new.expr.ts meta.brace.round.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts new.expr.ts string.quoted.single.ts punctuation.definition.string.begin.ts + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts new.expr.ts string.quoted.single.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts new.expr.ts string.quoted.single.ts punctuation.definition.string.end.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts new.expr.ts meta.brace.round.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts punctuation.terminator.statement.ts +> // .... + ^^^^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts punctuation.whitespace.comment.leading.ts + ^^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts comment.line.double-slash.ts punctuation.definition.comment.ts + ^^^^^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts comment.line.double-slash.ts +> }; + ^^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts + ^ + source.ts meta.function.ts meta.block.ts meta.arrow.ts meta.block.ts punctuation.definition.block.ts + ^ + source.ts meta.function.ts meta.block.ts punctuation.terminator.statement.ts +>} + ^ + source.ts meta.function.ts meta.block.ts punctuation.definition.block.ts \ No newline at end of file diff --git a/tests/cases/Issue672.ts b/tests/cases/Issue672.ts new file mode 100644 index 00000000..3ebafaa3 --- /dev/null +++ b/tests/cases/Issue672.ts @@ -0,0 +1,14 @@ +export function computed(...watchedProps: K[]) { + if (watchedProps.length < 1) throw new Error('@computed() decorator must have at least one property argument'); + + return >( + _target: T, + _prop: string | symbol, + desc: TypedPropertyDescriptor + ) => { + if (!desc.get) throw new Error('The `@computed()` decorator must be used on `get` method.'); + if (desc.set) throw new Error('The `@computed()` decorator cannot be used with `set` method.'); + if (desc.value) throw new Error('The `@computed()` decorator cannot be used with a regular function.'); + // .... + }; +} \ No newline at end of file