-
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
Discussion: TypeScript Output #5307
Comments
Just as a general, fairly strongly held desire — I do not want core CoffeeScript to add syntax for types, or TypeScript. I feel like moving in that direction is the opposite of the spirit of what CoffeeScript was trying to accomplish in the first place. But that doesn't mean it's not totally useful, and fair game for a fork or sister project. For prior art, see TypedCoffeeScript: https://github.com/mizchi/TypedCoffeeScript |
Yes, arguably it is. My perspective is that I work at a big company, and many big companies are flocking to TypeScript. It might get to the point where if I want to be able to keep using CoffeeScript at work at all, I’ll need to write CoffeeScript that integrates well with TypeScript. It’s sort of like what we went through with JSX: if CoffeeScript didn’t support JSX, it wouldn’t have full support for React, which is kind of a big deal since React is the most popular frontend framework. If CoffeeScript doesn’t support TypeScript output, there are certain developers who won’t be able to use CoffeeScript. That troubles me. At this stage in the project I feel like the top priority is maintaining and growing our community; CoffeeScript has long ago accomplished the philosophical goals it set out to achieve, perhaps far beyond anyone’s wildest expectations (see |
I've been thinking about this for years. Unlike Jeremy I have never seen static type-checking at odds with CoffeeScript. This then really poses the question: What value do I see in CoffeeScript? After all the advancements in ES6, the remaining value has been syntax. So CoffeeScript has great, whitespace significant syntax, is expression-based, but lacks type-checking and a second crucial tool of today - pretty-printing. I've debated this here: https://xixixao.github.io/dilemma/ (all my opinions, might inaccurate and outdated). The conclusion I got to was that the best course of action was to bring the better syntax to ES6, instead of porting type-checking and pretty-printing to CoffeeScript. The result was https://xixixao.github.io/lenientjs/ . This is why I'm commenting here, as Lenient is an exhaustive approach to whitespace significant syntax for ES6 and its typed variants. It could come in handy if you need to find syntax that supports both TS and CS-like syntax. Needless to say I don't think it's possible to do this without huge, breaking changes to CS syntax. (of course Lenient has the additional huge advantage of being able to use it directly on an ES6 codebase, if the editor support was good) |
CoffeeScript already supports type checking via Flow: https://coffeescript.org/#type-annotations. Obviously that’s not the same as TypeScript, but it’s not a complete lack of support either. CoffeeScript 2.5.0+ can be pretty-printed in Prettier via https://github.com/helixbass/prettier-plugin-coffeescript. |
What about to enable compiler plugins for parsing (tokenizer, lexer) and output? |
Yes, that would be great. That would also solve the problem of every new idea needing to avoid being a breaking change. The downside though is that in a project expecting plugins, developers would lose the ability to know what the intended output of a particular Anyway that's an entirely separate feature, one that we might need to implement if there's no way to add TypeScript support without breaking changes; but I think it deserves its own thread. |
I like the idea of use an extension to define which plugin to use. This will be perfect to typed coffee. However i believe the user may have a good reason to use a plugin to change the compiler behavioral and the output itself, for some task or target, without losing the compatibility with vanilla CoffeeScript. So, what i mean is: Extension is probability the better way to enable a plugin, however a CLI argument to globally apply a plugin may steel be useful. If the user wants to change the compiler behavior, it is they benefit and responsibility. |
I was once huge coffeescript fan. I still prefer the syntax, but the world has changed a lot since the introduction of coffeescript. Most of the features have been incorporated into EcmaScript, and now TypeScript is almost becoming the de-facto standard, whether you like it or not. I have to admit that the TypeScript tooling is excellent, and it's hard to get back to old way after using it for a while. I would love to see CoffeeScript continuing it's life as alternative syntax for TypeScript. That way it could benefit from the huge momentum of TypeScript ecosystem, while offering an unique benefit – the syntax, for us who appreciate it. |
Would a simpler syntax for flow comments achieve the goals of this discussion? I'm certain there's tooling to generate |
TypeScript supports reading types from JSDoc comments, which CoffeeScript already supports. I've been meaning to write a section in the docs explaining this; if anyone wants to beat me to it please feel free. I think this is probably the best solution possible at the moment, and we should definitely keep looking into alternatives. |
I just did some experimenting with JSDoc and coffeescript using meteor. This is what I found:
|
I’m not sure what this means. The TypeScript compiler doesn’t support CoffeeScript files, that much is clear, so you always have to have
This would be very nice. I think what’s needed is for the JS files to be autogenerated while you work, and put in a place where |
I assume @JanMP's goal would be able to write Alternatively, and beyond Meteor, it'd be nice to create a Incidentally, for the non-type-annotation features of TypeScript listed on the wiki, such as I must say I'm excited by the possibility of adding (nicer syntax for) TypeScript compatibility to CoffeeScript, ideally with a thin layer similar to how JSX got added (and ideally also not even requiring a different file extension). I will keep you posted on any progress I make... |
I started a branch that adds basic type annotation support. For example: i ~ number
i = 5
i = 'hello'
j ~ number = 10
zero ~ -> number
zero = -> 0
f ~ (i ~ number) -> number
f = (i ~ number) ~ number -> i+1
g = ->
i ~ number
i for i in [0..10] generates the following TypeScript: var f: (i: number) => number, g, i: number, j: number, zero: () => number;
i;
i = 5;
i = 'hello';
j = 10;
zero;
zero = function() {
return 0;
};
f;
f = function(i: number): number {
return i + 1;
};
j;
g = function() {
var i: number, k, results;
i;
results = [];
for (i = k = 0; k <= 10; i = ++k) {
results.push(i);
}
return results;
}; TypeScript handles this output and reports the error on Currently, the branch can use the Currently supported types include identifiers (
Note that the new notation allows a user to declare a local variable that has the same name as a parent scope ( It's definitely still a work in progress. There are probably still some bugs as I continue to figure out the parser, and many more features to add. I also don't support the AST yet. I could use some guidance on the best way to proceed. If people want to collaborate on this, they could submit PRs against my branch. I could also start a draft PR here if that would be helpful and not too noisy (I believe they still generate email notifications on every push). I guess it depends how much those watching this repo would like to know about advances on this branch vs. just being told there's a semi-finished product. But it might be nice to have a dedicated thread to discuss the approach, unless this issue is the place. If there's interest, we could start a |
This is very impressive! Great work! A few preliminary thoughts:
|
Nice work! Personally I'm in favor of breaking backward compatibility in exchange for first-class type support with nice syntax, which does not feel a compromise or afterthought. CoffeeScript does not have much to lose in current situation. Just a quick note, that AFAIK simple variable typing with primitives alone doesn't bring much value, since the typescript compiler is smart enough to determine the types from initial values, although I've no idea if that works with |
@GeoffreyBooth Thanks for the quick positive feedback! Here are some responses / further comments:
@jholster Thanks also for your feedback!
|
This is probably way too ambitious, but instead of outputting TypeScript we could output JSDoc annotations. Then One other thing to consider is |
Hmm, interesting idea. I'm not very familiar with JSDoc so don't know how much feature parity it has to TypeScript. But given the extensive work to support JSDoc already in CoffeeScript, it's quite plausible that this could be done... in some ways, this might make type annotation easier (no hoisting, though I already did it, so not easier than curriously). But I'm not sure about the other features. The filename extension issue could also be addressed by my previously proposed (but still hypothetical) |
A small update: I implemented object types. It's particularly fun to be able to use CS indentation-based notation to write these: object ~
key: string
value?: any
object =
key: 'one'
value: 1
object =
key: 'none' This translates to the following TypeScript (which var object: {key: string, value?: any};
object;
object = {
key: 'one',
value: 1
};
object = {
key: 'none'
}; I wondered about using
|
You all are doing the lord's work. I'll throw out that it would be nice if there were an option to output AssemblyScript as well: https://www.assemblyscript.org/. There is a good bit of WASM based blockchain stuff coming down the pipe and it would be awesome to have a clear, readable language to build wasm without having to mess with c++ or rust. It looks like AssemblyScript is a strict subset of Typescript, so I'm hoping it 'just works', but there may be some transpiring that breaks things. Here are some of the quirks: https://www.assemblyscript.org/basics.html#quirks |
@skilesare Thanks, I wasn't familiar with AssemblyScript. That's certainly a stretch goal, but I agree that it'd be nice if it'd be easy for a user to stay within the subset of TypeScript that it offers. Their intro example looks fairly easy... but e.g. CS converts This seems like one argument in favor of outputting TypeScript instead of JSDoc. More generally, the extensive tooling around TypeScript (e.g. perhaps also Deno of #5150) are probably further arguments for TypeScript output — while |
Outputting TypeScript is also likely far less work, and includes more information than JSDoc. There are things you can express in TypeScript that aren’t supported in JSDoc. |
I lean in the same direction as Jeremy. To me TypeScript and CoffeeScript are contradictory and must not be merged. It's not just that a CoffeeScript developer needs to be familiar with the syntax to a certain extent, they might also have to read/understand/update code written with said new syntax, rather than just glimpse at it. I expect that once people/projects start over-using type declarations (you know they will), we'll all have to deal with code that's hard to read and thus hard to maintain. Regarding CoffeeScript at the workplace: |
@Inve1951 Thanks for your input! Adding types to CoffeeScript is certainly not for everyone, and that's why it's optional. You could make the same argument for JSX: if you really want to use React, why not just switch to the official JSX language? But I take it from your recent bug report that you use CoffeeScript's JSX support. (As an aside, JSX is so much nicer when I don't quite follow your argument, so if you don't mind, I'd like to challenge a few points:
Type checking also has a significant advantage to someone writing CoffeeScript code, or for CoffeeScript code that uses TypeScript code. I don't want to stop writing in CoffeeScript, but I also want the extra bug checking that type checking affords; I routinely find and fix bugs that would have been detected by a type checker, so typing would save me time. I believe there are many others in this boat, though it would be interesting to do a survey.
Are you claiming that JSDoc comments such as add = (a ###: number###, b ###: number###) ###: number### -> a + b are easier to read than the proposed syntax add = (a ~ number, b ~ number) ~ number -> a + b ? It's also worth keeping in mind that an example like the above doesn't need any types, because TypeScript can often derive types automatically. So most of the time "typed" CoffeeScript would be the same as untyped: add = (a, b) -> a + b
People will write ugly code in any language. 🙂 I believe adding optional types to CoffeeScript enables clean typed code (much cleaner than TypeScript), just as CoffeeScript today enables writing clean untyped code. I have a harder time seeing that CoffeeScript with JSDoc is a fun way to write typed code. Correct typing is no small feat, so I doubt there will be a proliferation of types like you suggest. I am part of a ~17,000-line open-source JavaScript project that added Flow typing a couple years back. It took months to accomplish. For small projects, there's no reason to add types; it would just slow you down. But types make large codebases much easier to maintain. For comparison, I believe Python is generally considered to be one of the most readable programming languages, and it added optional typing support in 3.5. Most Python code doesn't use optional types, and that seems fine to me.
It's also what several CoffeeScript users want. Dozens reacted to the original post, a few have posted here, and I personally know several others, but I suspect there are many more. To be clear, CoffeeScript is my primary language of development, and has been for several years. I don't write TypeScript code because it's not (well) supported by CoffeeScript.
I maintain a bunch of TypeScript and Flow code too, despite knowing mostly JavaScript and CoffeeScript. I don't find it hard. I only wish that the code were in a typed CoffeeScript so that the notation could be that much better. By preventing people from conveniently writing types in CoffeeScript code, you push people (such as yourself) to TypeScript, which makes it harder for CoffeeScript fans to maintain that code.
I agree: Python words like |
In fact I am. But this is primarily due to the visual separation and could of course be adapted by editors when this feature lands. The typing being faded makes it less prominent to the eye allowing you to read the rest more easily. Not very relevant here but since you brought it up: render: ->
{ userIds } = @state
<div class="users">
{ userIds.map (userId) ->
<User id={userId} />
}
</div> Looking at this now I gotta say it's not very readable. So perhaps GitHub's code blocks aren't a good measurement for readability after all. I'm glad you took my feedback with a smile and am looking forward to seeing where you guys take this. |
As someone else who prefers Coffeescript syntax but sees the benefits/power of Typescript (and is willing to do some hacking on compilers), not to rain on any parades (I think any hacking/investigation of it is a good thing) but for similar reasons that I abandoned the run-ESLint-against-transpiled-JS approach in favor of Basically I don't see how you could get eg in-editor type hints without something very contorted like writing your own Language Server Protocol implementation which tried to map the original source to the transpiled Typescript, forward the request to its Language Server Protocol implementation ( So I started poking around the Typescript compiler. I've only taken baby steps, but there's a lot that seems to recommend the approach of using the Typescript compiler as the starting point (rather than the Coffeescript compiler) - the Typescript compiler already has its own baked-in concepts of different source language variants with different syntaxes (eg Screen.Recording.2021-04-21.at.9.40.20.PM.movPretty cool! This would also presumably allow for seamless hybrid Typescript/Coffee-Typescript codebases (like how now So then if what we'd all probably more or less picture is something that has as much of the syntactic 🌈 ✨ of Coffeescript as possible (while supporting all Typescript language features), the question becomes how hard will it be to slap that into the existing Typescript compiler frontend. From what I know, the rewriter step is pretty important to support some of the Coffeescript syntax (and that doesn't currently exist in the Typescript compiler) and the Typescript compiler uses a recursive-descent parser (LL?) rather than a grammar-generated one (LR?) I guess I've just been planning to gingerly poke my way around the Typescript compiler codebase until I start wrapping my head around how to implement syntactic features, but if anyone else has interest that could help move things forward! |
I’m strongly averse to breaking changes for the purpose of adding a new feature. We introduce breaking changes to fix bugs, or to (sometimes) match ES output for equivalent syntax, which is arguably also a bugfix; but that’s about it. From the perspective of a user who doesn’t care about TypeScript support, having a random semver-minor bump of CoffeeScript introduce a breaking change for a feature you don’t want would be extremely frustrating. We can do this without breaking changes. We owe that to our users. CoffeeScript is a mature project with lots of users who want to upgrade only to stay current with new ES syntax (like #5391) and they don’t want to need to run codemods or potentially pore over an old codebase because a minor bump of CoffeeScript introduced a breaking change. |
I've been working on my own language that inherits many features from CoffeeScript and additionally supports a large portion of TypeScript syntax. In my language, something like I haven't documented Storymatic much yet, but I'm hoping that I'll get full test coverage within 2 weeks and documentation within a month, but it'll take a while. I noticed there was a comment saying that |
The TypeScript CDK for the Internet Computer has launched. It would be lovely to write typedcoffeescript for it! https://github.com/demergent-labs/azle |
That's a good point: My current favorite notation for variable type declaration is probably for let x in list
queueMicrotask -> console.log x instead of for x in list
do (x) -> queueMicrotask -> console.log x Storymatic looks cool, though I find the shift from arrows to |
Sorry @edemaine, I haven't updated the docs yet. I removed the In my language, I also included a Here's how the
let a;
let a: number;
let a = 32;
let a = 56;
if (true) {
a = 78;
}
if (true) {
let a = 54;
} |
We could also have a keyword such as for scope x in list
queueMicrotask -> console.log x would compile to this: var i, len;
for (i = 0, len = list.length; i < len; i++) {
let x = list[i];
queueMicrotask(function() {
return console.log(x);
});
} |
I've been working on a solution to this https://github.com/DanielXMoore/Civet Along the lines of Jeremy's preference it is a sister project that has ~98% compatibility with existing CoffeeScript while adding support for TypeScript types and reconciling ES features. Take a look. Your wildest dreams might just come true. |
Is there ever likely to be any consensus/progress on this? I’m digging into using Qwik for a bunch of projects going forward, which unfortunately is pretty much TypeScript (and JSX) only, currently… Being able to compile CoffeeScript -> TS + JSX, without actually having to write that syntax (both are ugly as shit 😖) would be super sweet! Related to QwikDev/qwik#2878. |
Just an update that I'm no longer working on my TypeScript branch of CoffeeScript, and have instead shifted my efforts to Civet (including some nice JSX improvements). I'm not sure we have anyone using Civet in Qwik yet, but we'd be very happy for this to happen. (See this issue for some related discussion.) |
My opinion hasn’t changed. I’m happy to add TypeScript support (or a subset of TypeScript syntax support) if we can find a way to do so without breaking changes; and someone wants to put in the effort. Perhaps some of the work in Civet could be ported over. Another option is to improve our block comments support to allow using them for JSDoc comments that can be typechecked by Lastly, JSDoc could be the output of some new syntax. So say there’s some syntax that someone comes up with that’s non-breaking and allows for defining the types of parameters and types and so on. That could be compiled into inline JSDoc comments that TypeScript can understand, while still preserving that CoffeeScript itself is just outputting runnable JavaScript files (with these extra comments). This is perhaps the best of all, as no extra build steps are required; |
I will admit, I don't have time to go through the entire thread right now. But I used coffescript as my primary language on many many projects. I've read the coffeescript compiler and that taught me to design programming languages (and gave me a very thorough understanding of the language itself). As I expanded my career, I worked on microservices, devops, and many other areas of software in addition to front end development. During that time I came to see the absolute necessity of typed code. When you're working on a large project with 40+ other engineers, lack of types is a disaster. It slows down development and increases frustration by a massive amount. I loved coffeescript. It's my favorite language syntax-wise. It's powerful, expressive, and beautiful in my opinion. Like I said I can read it natively faster than I can read the equivalent JS which is not the same for many people. I'd love to use it again. But after 15+ years in the field, I would never consider starting a new project without typescript. It's a non-starter. Lack of types is something junior devs appreciate because it gives them the flexibility to "get something running". Senior devs who work on tiny teams with only other senior devs might like it too. You can probably coordinate enough and your projects are small enough to make it work. But for anyone doing enterprise engineering on large projects, lack of types is a silly foundational error that your project will likely never recover from. It's a ridiculous proposition. And unfortunately that eliminates coffeescript from any consideration whatsoever.
If the spirit of coffeescript is to have a language for small projects with one or two devs, and eventually die as a language than I agree. If the spirit of coffeescript is to make writing javascript in the real world simpler, more concise and readable, and more maintainable, then I believe this is exactly contrary to what coffeescript is designed for. Coffeescript should be designed for Javascript as it is actually used and like it or not, that is typescript now. I would advocate that coffeescript should include 1st class support for typescript and not even worry about breaking changes. Make it v3. Unless coffeescript has full typescript support, you're ignoring the vast majority of real world javascript usage. I don't doubt that there are more projects using javascript than typescript. But they're likely tiny projects with a single maintainer, or abandoned. If you go by number of engineers currently working on projects or amount of code written today, you'd fine that typescript is ubiquitious. If an ardent supporter of coffeescrpt, someone who loves the language and wrote it for years, can't even use it myself or recommend it in good conscience, who exactly is coffeescript for? It will never grow, it will only dwindle until the last maintainer decides they're going to work on something else. For coffeescript to survive it needs full typescript support. It needs to evolve with the times or it will die. And I really hope the community can decide to evolve it rather than let it die regardless of the inconvenience of breaking changes. |
Nevermind, just read about Civit. Seems like that's the future. If anyone here is curious about whether static types are really important or not, I encourage you to explore some other languages and work with larger projects / teams / organizations. At minimum you can prove to yourself I'm wrong. It can't hurt. Take care |
The above comment is incredibly hostile propaganda and reminds me of the
It also ignores the maintainer's most recent reply just above (#5307 (comment)):
I recall here how my very first open source contribution (#3946), where @GeoffreyBooth helped me to fall in love with open source for life, managed to achieve backwards compatibility across a very surprising divergence between Mac and Linux command-line parsing (#3946 (comment)). Part of the spirit of CoffeeScript I value is how our compiler remains so simple and thoughtfully architected that we have sufficient inertia to spend our time to divine a beautiful unifying solution that makes our future work simpler, instead of getting stuck on the hamster wheel of "move fast and break things". Can we rise to meet both of the challenges laid down by maintainers at the top and bottom of this thread? Can we devise a non-breaking syntax to generate simple and readable code, equally ready for the browser or a build pipeline? Can we carry on our tradition of innovation, and discover a new way to honor the spirit of what CoffeeScript was trying to accomplish in the first place? Making new syntax is working with the stuff of pure thought. It's not like a boolean satisfiability problem, mechanically mapping requirements to features, accepting approximate solutions. CoffeeScript programmers experience the language as an extension of their mind and body. What does a type taste like? When you pick up a function, how much does it weigh? I dutifully used flow types in block comments. It was fine. But it was a workaround. And it felt like exactly what it was: writing two separate languages side-by-side in the same file. Code switching that often is exhausting! If I'm reading it right, we have just been given a well-defined open problem. Here we have the chance to do something truly novel. |
Ok, I spent some time playing around with this: https://github.com/jashkenas/coffeescript/compare/main...cosmicexplorer:jsdoc-syntax?expand=1. I'm not proposing any specific syntax right now, but instead just did some background research.
|
Ok, I tried to make things easier, but I ended up with a completely separate syntax proposal that I've wanted from coffeescript for many years which resolves the conundrum I was having. I will create a separate issue for that, but to summarize: use
|
I realized that when we restrict the type annotation syntax to top-level assignments as above, we also assume there is no subsequent redefinition of the same name, e.g.: # we generate a special `var f` block for this
f{string} = "asdf"
# we would have to error against this
f{number} = 3 generate
|
Just a comment to say that I was so happy to see this pop up on my feed. I miss coffeescript :) As these AIs get better and better at programming I think we get back to a place where a simpler, more elegant language could actually emerge as we can push button convert entire libraries with generated tet runners and complete coverage. |
@cosmicexplorer, why not use the I believe, writing in plain english is more coffeeish.
Both should give the same result, but the second is more "delicious". Thinking only on type annotations it is enough, but I dislike this idea. I think we need full typescript power. With typescript output in mind, I don't know how hard it will be to recognize where is a declaration and where is a type cast, but I believe it is possible and not a problem. So, this case must be possible: A as MyType
A = {} as MyType output: let A: MyType;
A = {} as MyType; Well, the double meaning of the operator If different operators are necessary, the better I can propose is to use A be MyType
A = {} as MyType |
I certainly did not mean to come across as hostile. I took a strong position on the topic in the hopes that the maintainers might consider this important. I can't thank jashkenas enough for creating the language, and want to express my immense gratitude for all the hard work the other contributors have made over the years. I do not want to sound entitled or ungrateful whatsoever. I was using coffeescript 15 years ago! That the language is still actively maintained is a remarkable accomplishment. It's my favorite language to write, and if I didn't care so much about it I wouldn't have bothered commenting.
I didn't mean to make anyone feel inadequate. Sincere apologies and thanks for your contributions. Rest assured I will not be asking for any access to the code, nor do I have plans to submit any PRs for the foreseeable future.
Interesting idea. I don't think the JSDoc is actually typescript, and I don't think it supports everything typescript supports. It does sound like a decent way to get some static type checking, but I'd be hesitant to make this change if it will make typescript support any more difficult to implement. It might end up being too little for those who need typescript, and rarely used by people who don't think about types anyway. Thank you for your post. I did have a longer response typed out but I think it largely rehashes points I've made before, and feels unnecessary/off-topic in this thread. As I mentioned above, I wouldn't post this unless I cared about the language. None of this is an attack on the language, or meant to dismiss in any way all of the extremely hard work so many people have put in over the (many) years. My gratitude is immense and out of the dozen or so languages I have written regularly, it's still my favorite syntax. I truly just want to see the language remain relevant and gain in popularity, and I'm just not seeing how that happens without typescript. |
You may think that, but then you'd be rather wrong - JSDoc is very close to being feature-complete, you can do all sorts of advanced stuff like generics, type casts or type definitions. Most exceptions can be externalized into separate type definition files. Which is admittedly annoying, but well it works... Also I want to re-emphasize that while having a dedicated, backward-compatible TS-in-CS syntax would be neat, you can instead already also output JSDoc with CoffeeScript by writing JSDoc like |
@brandon-fryslie: I really appreciate your heartfelt and thoughtful response here! I absolutely understand and share your passion for improving the language ^_^! I should have made it clear I was characterizing a string of comments, and yours just happened to be the most recent (I'm sorry!). I really appreciate the time and care you took to elaborate on your thinking here--I'll make sure to give you the same courtesy in the future!
I totally agree! Geoffrey Booth described a path towards a middle ground with JSDoc, but I don't know anything beyond that outline! I'm trying to poke at it--see my Thanks again so much for your thoughtful reply. I would love to work with you on this if we can figure out how to get typescript a little closer to CoffeeScript! @aurium: I love the idea of When I was working on the branch that became #5475, I was also looking to use
That reminds me, I have a lot of emacs lisp code for coffeescript I haven't upstreamed yet...... But! My goal with #5475 was going to be a middle ground--no |
@aurium: this is one idea I had regarding Summary
@aurium @brandon-fryslie: I prototyped I think the work on the EDIT: I'm sorry @aurium, I missed where you already discussed the use of
I totally agree! I created #5474 as a start (that's only function params), but I am about 75% confident that CoffeeScript already has a very strong differentiation between lvalue and rvalue expressions even at the grammar level, and that we can use this to introduce new syntax without breaking changes! |
One other distinction I think would be good to make:
JSDoc output gives us (1) without involving TODOJSDoc output
After #5475 (see the changes to
|
hmmmm I think I accidentally just solved the JSDoc half of this? #5477 e.g. > coffee -c -b -s --no-header <<EOF
y = 3
###* @type {number} ###
x @= 3
EOF
var y;
y = 3;
/** @type {number} */
var x = 3; I'm going to try massaging |
I think I was confused: Please take a look at #5477 for more context, but the key is:
###*
* @type {number}
###
x @= 3 becomes: /**
* @type {number}
*/
var x = 3; Here is an example of running the # e.g. run these shell commands from the repo root (you'll need to have npm installed typescript):
; cat > test-map.coffee <<EOF
y = 3
###* @type {string} ###
x @= 3
EOF
; coffee build-support/typescript-compile.coffee test-map.coffee
test-map.coffee:4:1 - error TS2322: Type 'number' is not assignable to type 'string'.
4 x @= 3
~
# it also generates adjacent .js and .js.map files:
; cat test-map.js
var y;
y = 3;
/** @type {string} */
var x = 3;
//# sourceMappingURL=test-map.js.map
; cat test-map.js.map
{
"version": 3,
"file": "test-map.js",
"sourceRoot": "/home/cosmicexplorer/tools/coffeescript",
"sources": [
"test-map.coffee"
],
"names": [],
"mappings": "AAAA,IAAA;;AAAA,CAAA,GAAI,EAAJ;;;AAGA,IAAA,CAAA,GAAK",
"sourcesContent": [
"y = 3\n\n###* @type {string} ###\nx @= 3\n"
]
}
# finally, it also generates a .d.ts type definition file:
; cat test-map.d.ts
declare var y: any;
/** @type {string} */
declare var x: string; |
@cosmicexplorer I think it would be great to modify TypeScript (tsc but also the API) to respect sourcemaps in the input |
Similar to how the CoffeeScript compiler outputs JSX, it could output TypeScript source code. This could then be piped to the TypeScript compiler (or Babel’s TypeScript plugin) for type checking before being further transpiled into runnable JavaScript. This would provide an alternative to Flow for type annotations in CoffeeScript, and potentially better compatibility with other projects that use TypeScript. It could also support better code hinting in supported environments, similar to what Visual Studio Code provides for TypeScript.
I’ve started a wiki page that I invite anyone interested to contribute to, to consolidate all the syntax additions that TypeScript adds to JavaScript that we might potentially want to support in CoffeeScript’s output. For example, type annotations such as
const foo: number = 3
. I think the first step is to flesh out this page to see what all of TypeScript’s unique constructs are, to get a sense of the scope of the challenge.Once that’s done, there are two broad approaches to implementing TypeScript output from CoffeeScript input:
Add new syntaxes to CoffeeScript that can be converted to the various TypeScript syntaxes, similar to how JSX was added. This would enable TypeScript output to be added without requiring a breaking change, and using the existing compiler.
Make breaking changes to the syntax to add support for all the TypeScript things we want to support. This would essentially require a new file format, e.g.
.tcoffee
, and either a fork of the compiler or a dramatic rewrite of the existing one.For example, the TypeScript code
const foo: number = 3
can’t be implemented in CoffeeScript asfoo: number = 3
, becausefoo: number = 3
is already valid CoffeeScript; it transpiles to the JavaScript{foo: number = 3}
. The CoffeeScript syntax would need to be something likefoo:= number = 3
(or some other symbol(s) besides:=
), to use syntax that doesn’t already parse today.If the list of desired TypeScript syntaxes that folks add to the wiki page isn’t too long, and we can come up with acceptable non-breaking ways to support all of them, then the first option (add to the existing compiler) is viable. Otherwise the second option (
.tcoffee
) will be the only way. And of course it’s an open question as to whether either approach is worth the effort.If people don’t mind, let’s please not flood this thread with suggestions for syntaxes, like better ideas for my
:=
example. We can find a place for that, such as a new wiki page or an extension of the existing one. See also #4918; cc @jashkenas @lydellThe text was updated successfully, but these errors were encountered: