Skip to content
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

New feature: Typescript compiler #155

Closed

Conversation

znakeeye
Copy link

@znakeeye znakeeye commented Sep 7, 2021

Derived a Typescript compiler from the existing Javascript compiler.

  • Typescript compiler is happy + code is well-formatted.
  • Verified for a few languages.

I believe snowball will greatly benefit from this. Please consider a merge after scrutinizing all my tweaks. Particularly the build scripts... I did my best trying to figure out all parameters and stuff 😄

@@ -647,7 +685,7 @@ check_go_%: $(STEMMING_DATA_ABS)/%
fi
@rm tmp.txt

export NODE_PATH = $(js_runtime_dir):$(js_output_dir)
export NODE_PATH = $(js_runtime_dir):$(js_output_dir):$(ts_runtime_dir):$(ts_output_dir)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be cleaner to arrange to set this to just the paths that are relevant depending on whether we're doing javascript or typescript - then we don't have to worry that we might be pulling parts of the other one when running tests.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all Greek to me. I just did some guessing :)

import * as fs from 'fs';

function usage() {
console.log("usage: stemwords.js [-l <language>] -i <input file> -o <output file> [-c <character encoding>] [-p[2]] [-h]\n");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.js here...

if (!lc_name.match('\\W') && lc_name != 'base') {
let algo = lc_name.substr(0, 1).toUpperCase() + lc_name.substr(1);
try {
const stemmer = require(lc_name + '-stemmer.js');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.js here too ... which presumably means we're testing the JS stemmers, not the typescript ones!

@@ -0,0 +1,1308 @@

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is very similar to generator_js.c - from a maintenance point of view I think it would make more sense to share a single generator implementation between javascript and typescript and just parameterise the small number of differences - that way future fixes only need applying in one place rather than two (if there are two places to fix, inevitably one gets missed sometimes).

Also, it seems many of the differences are due to trying to format the generated code to match typescript code formatting conventions. I'm not sure how worthwhile a goal that is - having generated code with a basically readable formatting to aid debugging generator problems is useful, but coding conventions almost universally aim at making code more maintainable, and the generated code inherently doesn't need to be maintained directly.

So I'd be inclined to just tell typescript to shut up about code formatting (with more/broader eslint-disable magic comments), but if that's not possible we could format the javascript output in the same way.

There's also the approach the Go generator takes which is to run the snowball .go outputs through gofmt to mechanically reformat them to match Go coding conventions. That has the advantage that there's no snowball-specific work to do if new formatting checks get added.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're absolutely right on all points. Not sure if and when I will have time to do this though.

Magic comments would do, for sure. I believe the most important parts are:

  • Modern Typescript class syntax is preferred: export class SwedishStemmer extends BaseStemmer
  • Prefix all members and methods with this.

I'm no Javascript expert, but once you start mixing require() with some legacy libraries and the modern import syntax, the compiler doesn't seem very happy. That's the reason I created this PR in the first place.

mkdir -p $${dest} && \
mkdir -p $${dest}/$(ts_runtime_dir) && \
mkdir -p $${dest}/$(ts_sample_dir) && \
cp -a doc/libstemmer_ts_README $${dest}/README.rst && \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no doc/libstemmer_ts_README so make dist fails (hence the CI failures)

@ojwb
Copy link
Member

ojwb commented Sep 20, 2023

This PR still needs work, and #183 suggests a different approach:

My feeling is that there's not much point having a separate TS build, as TS-compatible types can be supplied by JSDoc without any loss of JS compatibility.

Thoughts? Should we close this PR in favour of taking that approach instead?

@ojwb
Copy link
Member

ojwb commented Sep 20, 2023

Taking that "thumbs up" as a yes, and closing.

@ojwb ojwb closed this Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants