Skip to content

✨ JavaScript #53

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

Merged
merged 3 commits into from
Apr 5, 2025
Merged

Conversation

NatoBoram
Copy link
Collaborator

@NatoBoram NatoBoram commented Apr 2, 2025

Summary by CodeRabbit

  • New Features

    • Introduced comprehensive JavaScript language support, including installation and usage guidelines.
    • Added a module that enhances parsing capabilities for multiple JavaScript file types.
    • Added a new type definition for language registration with relevant properties.
  • Tests

    • Implemented a dedicated testing environment to validate JavaScript code parsing functionality.
  • Chores

    • Updated package metadata and configured post-install routines to streamline integration and setup.
    • Added a new package for JavaScript language support, including necessary dependencies.

Copy link

coderabbitai bot commented Apr 2, 2025

Walkthrough

A new JavaScript language package, @ast-grep/lang-javascript, has been introduced. The changes add a README with installation and usage instructions, define a new LanguageRegistration type with corresponding registration values in both TypeScript and JavaScript, and set up a testing environment via a nursery script. A post-installation script and package metadata have also been provided to integrate the new language support into the ast-grep framework.

Changes

File(s) Change Summary
packages/javascript/README.md Added documentation detailing installation and usage of the JavaScript language support.
packages/javascript/index.{d.ts,js} Introduced a new LanguageRegistration type and exported a registration object, defining properties such as libraryPath, extensions, languageSymbol, and expandoChar.
packages/javascript/nursery.js Created a test setup that parses a JavaScript snippet using the @ast-grep/nursery package and validates syntax node identification.
packages/javascript/package.json Defined package metadata for @ast-grep/lang-javascript, including dependencies, scripts, and publish configuration.
packages/javascript/postinstall.js Added a post-install script invoking @ast-grep/setup-lang to configure the package upon installation.
.changeset/twelve-ties-punch.md Added a changeset entry indicating the inclusion of the @ast-grep/lang-javascript package.

Possibly related PRs

  • ✨ Bash #46: The changes in the main PR for the JavaScript package and the retrieved PR for the Bash package both introduce a new LanguageRegistration type and a registration constant, indicating a direct relationship at the code level.
  • ✨ Haskell #50: The changes in the main PR for the JavaScript package and the retrieved PR for the Haskell package both introduce a new LanguageRegistration type and a postinstall.js file, indicating a strong connection in their implementation of language support within the ast-grep framework.
  • feat: C# language #41: The changes in the main PR for the JavaScript language package are related to those in the retrieved PR for the C# language package, as both introduce a new LanguageRegistration type and a similar structure for their respective README, index, and postinstall files.

Suggested reviewers

  • HerringtonDarkholme

Poem

I'm a coding rabbit, hopping with glee,
New language support sets my code spirit free.
Parsing JavaScript in playful delight,
Registration and tests working just right.
With carrots of code and a joyful sprint,
Cheers to new features—I'm in it to win it! 🐰


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6579d68 and c135b3a.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (7)
  • .changeset/twelve-ties-punch.md (1 hunks)
  • packages/javascript/README.md (1 hunks)
  • packages/javascript/index.d.ts (1 hunks)
  • packages/javascript/index.js (1 hunks)
  • packages/javascript/nursery.js (1 hunks)
  • packages/javascript/package.json (1 hunks)
  • packages/javascript/postinstall.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (7)
  • packages/javascript/postinstall.js
  • packages/javascript/index.d.ts
  • .changeset/twelve-ties-punch.md
  • packages/javascript/nursery.js
  • packages/javascript/index.js
  • packages/javascript/README.md
  • packages/javascript/package.json

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (5)
packages/javascript/README.md (1)

14-24: Usage example is concise and demonstrates the key functionality.

The example demonstrates the essential steps for using the package:

  1. Importing the JavaScript language module and NAPI functions
  2. Registering the dynamic language
  3. Parsing JavaScript code and accessing the root node

Consider adding another example demonstrating a more complex pattern matching use case to help users understand the full capabilities of the package.

packages/javascript/index.js (2)

6-7: LGTM! Consider adding TypeScript extensions if applicable.

The extension list correctly includes common JavaScript file extensions. If this parser is intended to support TypeScript files as well, consider adding 'ts' and 'tsx' extensions to the list.


8-8: Consider adding a comment explaining the expandoChar's purpose.

The expandoChar property is set to '$', but its purpose isn't immediately clear to someone unfamiliar with the codebase. A brief comment explaining how this character is used in AST queries would improve maintainability.

packages/javascript/package.json (2)

4-4: Add a package description.

The description field is empty. Consider adding a brief description of what this package does, such as "JavaScript language support for ast-grep" to improve discoverability and provide context.


22-22: Add author information.

The author field is empty. Consider adding the author's name, email, or organization to properly attribute the package.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 002639c and 1f7c972.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (6)
  • packages/javascript/README.md (1 hunks)
  • packages/javascript/index.d.ts (1 hunks)
  • packages/javascript/index.js (1 hunks)
  • packages/javascript/nursery.js (1 hunks)
  • packages/javascript/package.json (1 hunks)
  • packages/javascript/postinstall.js (1 hunks)
🔇 Additional comments (7)
packages/javascript/postinstall.js (1)

1-4: Looks good!

The postinstall script correctly imports and calls the postinstall function from the @ast-grep/setup-lang package, passing the current directory. This is a common pattern for Node.js packages that need to perform setup steps after installation.

packages/javascript/nursery.js (1)

1-16: Testing setup looks good and verifies the JavaScript parsing functionality.

The nursery setup correctly configures the testing environment for JavaScript:

  1. It imports necessary dependencies
  2. Sets up the test environment with appropriate configuration
  3. Includes a test runner that verifies the parser can correctly identify a lexical declaration

This follows the pattern used by other language packages in the ast-grep ecosystem.

packages/javascript/index.d.ts (2)

1-7: Type definition looks good.

The LanguageRegistration type correctly defines the expected structure for language registration:

  • Required properties: libraryPath and extensions
  • Optional properties: languageSymbol, metaVarChar, and expandoChar

This type follows the standard pattern used by other language packages and provides clear typing information.


9-10: Default export is properly typed.

The registration constant is correctly typed as LanguageRegistration and exported as the default export.

packages/javascript/README.md (1)

1-12: Installation instructions are clear and complete.

The README correctly specifies the necessary installation steps for a pnpm project:

  1. Installing the language package itself
  2. Installing the required @ast-grep/napi dependency
  3. Optional installation of @tree-sitter/cli for environments lacking prebuilt binaries

This provides users with the information they need to get started.

packages/javascript/package.json (2)

1-47: LGTM! Package structure follows npm conventions.

The package.json is well-structured with appropriate scripts, dependencies, and configuration for integration into the ast-grep ecosystem. The build process using tree-sitter and the postinstall script for setup follow good practices for native modules.


23-23:

✅ Verification successful

Verify if ISC license is intended.

The package specifies ISC license. Please verify if this matches the license used by other ast-grep packages or if it should be aligned with the project's overall licensing strategy.


🏁 Script executed:

#!/bin/bash
# Check licenses of other ast-grep packages
echo "Checking licenses of other ast-grep packages:"
find . -name "package.json" | grep -v "node_modules" | xargs grep -l "\"license\":" | xargs grep "\"license\":"

Length of output: 907


Licensing Consistency Confirmed

The verification shows that the vast majority of the ast-grep subpackages—including packages in Angular, C, C++, C#, Go, Python, SQL, and others—use the ISC license. The packages/javascript/package.json already aligns with this pattern by specifying ISC on line 23. (Note that the root package.json uses MIT, which appears to be an intentional difference in overall licensing strategy.)

Thus, no changes are required regarding the ISC license in packages/javascript.

@NatoBoram NatoBoram force-pushed the feature/javascript branch 2 times, most recently from de054f7 to 6579d68 Compare April 4, 2025 21:02
@NatoBoram NatoBoram force-pushed the feature/javascript branch from 6579d68 to c135b3a Compare April 5, 2025 06:33
@HerringtonDarkholme HerringtonDarkholme merged commit 7eb4c81 into ast-grep:main Apr 5, 2025
3 checks passed
This was referenced Apr 6, 2025
@NatoBoram NatoBoram deleted the feature/javascript branch April 6, 2025 03:31
This was referenced Apr 22, 2025
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