-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Block comments should be placed above variable assignment, not declaration (Fix JSDoc etc) #5366
Comments
Yes, the block comments shouldn’t be hoisted with the The place to look to understand comments is #4572, in particular #4572 (comment), #4572 (comment), #4572 (comment), #4572 (comment). It’s a long thread, but those comments should give you a general idea of how comments work in the compiler. It’s a bit of a hack because comments aren’t part of JavaScript syntax itself (they’re not nodes in the abstract syntax tree); but this is the same approach that Babel takes, so it’s pretty solid. It’s probably either in |
@robert-boulanger found a similar issue with comment blocks above fat arrow class methods: phil294/coffeesense#1 (comment) |
I think #5395 could help with the original issue here. Currently, that PR doesn't push the I assume it's better to leave #5395 as is, so it's easier to review, and I can work on this after it gets merged. If you'd rather me work on it first, as a proof of concept that pushing |
Side note: I found another, slightly shorter workaround that does not require an extra line: ``###*
# @param a {string}
###
method1 = (a) -> Edit: I stand corrected, it does not always work. Example: a =
b: 1
``### abc ###
c: 2 -> |
…ral) by prepending them with two backticks ``" Revert "add test for jsdoc inside iife" It's not waterproof, see jashkenas/coffeescript#5366 (comment) This reverts commit 56b7982. This reverts commit 03acf8f.
I'm not convinced anymore this is the case, because sometimes, you need to declare and type a var before assigning it inside some callback: ###* @type {number} ###
var x
cb = =>
x = 2
null
cb()
console.log(x) not sure how this would be solved. Sure, instead of So there's two problems here:
It would be questionable to re-introduce the `var x` wouldn't work because The proper solution for the programmer is to make TL;DR: This is not a showstopper and the logic should still be changed as planned |
CoffeeScript doesn't allow variable declarations, only assignments. In your code where you have |
Sure! But then you'll have to mark In contrast, consider this JS code, perhaps a better example: /** @type {number} */
var x
var cb = () => {
x.toFixed()
};
x = 3
cb(); no type error, and runs successfully. Not possible with Not great code though, I understand that. You'd risk exposing yourself to some |
As I understand it, you don’t need the /** @type {number} */
var x;
x = undefined;
x = 3; This doesn’t error in the TypeScript playground: https://www.typescriptlang.org/play?#code/PQKhAIAEBcE8AcCm4DeA7ArgWwEaIE4C+4IwAUAG4CG+4AHgNxl3gC84GaAJogGYCWaRFyYt2AZiZA This does show that we need the JSDoc output above the |
ah cool. Not with (and also, you need to set language to JavaScript as JSDoc has no effect inside .ts files) |
Input Code
For example, if you want to output usable JSDoc to integrate with TypeScript:
Expected Behavior
Current Behavior
Possible Solution
Possible current workaround (pretty ugly):
Alternatively, you can of course do inline typed params
but this is not always a feasible solution of course
Context
Besides, should we maybe update the docs to state the possiblity of type-checking via JSDoc+TS? I know there is a TypeScript discussion issue going on in #5307 but this jsdoc thing is already possible.
I am currently exploring building a basic CS LSP implementation based on piping CS compiler output to TSC, bundled in a VSCode extension. It works pretty well so far, I'll post in the other thread soon (edit: POC / WIP here
The text was updated successfully, but these errors were encountered: