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

Remove unused plus typescript tightening #3527

Conversation

SpencerWhitehead7
Copy link
Contributor

Description

This is a bunch of fairly minor changes to remove unused files/packages and take advantage of some more recent typescript/js features, namely ?: in parameter definitions, ?. optional chaining, at .at(-x) instead of [arr.length - x]

There should not be any changes in functionality or type interfaces.

It will make the most sense looked one commit at a time.

Contributor

  • Test(s) exist to ensure functionality and minimize regression (if no tests added, list tests covering this PR); or,
  • no tests required for this PR.
  • If submitting new feature, it has been documented in the appropriate places.

Committer

In most cases, this should be a different person than the contributor.

Copy link

vercel bot commented Nov 9, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
marked-website ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 17, 2024 4:43am

Copy link
Member

@UziTech UziTech left a comment

Choose a reason for hiding this comment

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

Some of these changes could make marked slower like declaring a variable inside a loop instead of before the loop. I'm not sure if this is still the case but it would be nice to get an idea of how this change affects speed.

bower.json Outdated Show resolved Hide resolved
src/MarkedOptions.ts Outdated Show resolved Hide resolved
@UziTech
Copy link
Member

UziTech commented Nov 9, 2024

In terms of speed it looks like this may be faster with Node v22. Running npm run bench gives us a benchmark for marked against commonmark and master is giving me ~35% slower than commonmark and this PR is giving ~30% slower.

docs/demo/demo.js Show resolved Hide resolved
@SpencerWhitehead7
Copy link
Contributor Author

In terms of speed it looks like this may be faster with Node v22. Running npm run bench gives us a benchmark for marked against commonmark and master is giving me ~35% slower than commonmark and this PR is giving ~30% slower.

I still have the bench-100 file from this PR #3146. It says main takes 122ms and this branch takes 117, which I think is kinda within margin of error. It's not a big degradation at least.

Copy link
Member

@UziTech UziTech left a comment

Choose a reason for hiding this comment

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

Thanks! 💯

@@ -6,7 +6,7 @@ import type { Token, TokensList } from './Tokens.ts';

export class _Hooks {
options: MarkedOptions;
block: boolean | undefined;
block?: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

Note that these do not have the same meaning.

https://x.com/DavidKPiano/status/1856701854102557026

Although I think in this case that's okay.

lastToken.raw += '\n' + token.raw;
lastToken.text += '\n' + token.text;
this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
this.inlineQueue.at(-1)!.src = lastToken.text;
Copy link
Member

Choose a reason for hiding this comment

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

Not a fan of using ! but it is logically the same as the previous code.

We should look at making this safer in a follow up PR.

list.items[list.items.length - 1].raw = list.items[list.items.length - 1].raw.trimEnd();
list.items[list.items.length - 1].text = list.items[list.items.length - 1].text.trimEnd();
const lastItem = list.items.at(-1);
if (lastItem) {
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for making this one safe 👍

src/helpers.ts Outdated
@@ -72,7 +72,7 @@ export function splitCells(tableRow: string, count?: number) {
if (!cells[0].trim()) {
cells.shift();
}
if (cells.length > 0 && !cells[cells.length - 1].trim()) {
if (!cells.at(-1)?.trim()) {
Copy link
Member

@styfle styfle Nov 15, 2024

Choose a reason for hiding this comment

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

This looks like a bug.

Consider the case when cells = [].

console.log(cells.length > 0 && !cells[cells.length - 1].trim()); // false
console.log(!cells.at(-1)?.trim()) // true

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the catch. Since all the unit tests still pass, I wonder if for some reason cells.length always happens to be > 0 on this line. I'll fix it though.

@UziTech UziTech merged commit 1f579f7 into markedjs:master Nov 18, 2024
8 checks passed
github-actions bot pushed a commit that referenced this pull request Nov 18, 2024
## [15.0.1](v15.0.0...v15.0.1) (2024-11-18)

### Bug Fixes

* Remove unused plus typescript tightening ([#3527](#3527)) ([1f579f7](1f579f7))
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.

3 participants