Using the TypeScript compiler to fix erroneous Node.js snippets

Brittany Reid, Christoph Treude, Markus Wagner

Research output: Chapter in Book/Report/Conference proceedingConference PaperResearchpeer-review

Abstract

Most online code snippets do not run. This means that developers looking to reuse code from online sources must manually find and fix errors. We present an approach for automatically evaluating and correcting errors in Node.js code snippets: Node Code Correction (NCC). NCC leverages the ability of the TypeScript compiler to generate errors and inform code corrections through the combination of TypeScript's builtin codefixes, our own targeted fixes, and deletion of erroneous lines. Compared to existing approaches using linters, our findings suggest that NCC is capable of detecting a larger number of errors per snippet and more error types, and it is more efficient at fixing snippets. We find that 73.7% of the code snippets in NPM documentation have errors; with the use of NCC's corrections, this number was reduced to 25.1%. Our evaluation confirms that the use of the TypeScript compiler to inform code corrections is a promising strategy to aid in the reuse of code snippets from online sources.

Original languageEnglish
Title of host publicationProceedings - 2023 IEEE 23rd International Working Conference on Source Code Analysis and Manipulation, SCAM 2023
EditorsLeon Moonen, Christian Newman, Alessandra Gorla
Place of PublicationPiscataway NJ USA
PublisherIEEE, Institute of Electrical and Electronics Engineers
Pages220-230
Number of pages11
ISBN (Electronic)9798350305067
ISBN (Print)9798350305074
DOIs
Publication statusPublished - 2023
EventIEEE International Working Conference on Source Code Analysis and Manipulation 2023 - Bogota, Colombia
Duration: 1 Oct 20232 Oct 2024
Conference number: 23rd
https://ieeexplore.ieee.org/xpl/conhome/10356389/proceeding (Proceedings)
https://www.ieee-scam.org/2023/ (Website)

Conference

ConferenceIEEE International Working Conference on Source Code Analysis and Manipulation 2023
Abbreviated titleSCAM 2023
Country/TerritoryColombia
CityBogota
Period1/10/232/10/24
Internet address

Keywords

  • Error Correction
  • Node.js
  • Static Analysis

Cite this