Xbasic

convert_ts_to_js function

Syntax

dim result as c = convert_ts_to_js(files as c)

Arguments

filesCharacter

A CR-LF delimited list of TypeScript file names to convert to JavaScript.

Returns

resultCharacter

Returns a JSON string containing any errors that may have occured for each file that was converted. If no errors occured, results will be an empty JSON object. If errors do occur, each entry in the JSON object will have the following properties:

filenameCharacter

The TypeScript file that has the error.

errorCharacter

A message describing the error.

lineNumeric

The line number in the TypeScript file where the error occurred.

columnNumeric

The location on the line where the error occurred.

Description

Converts TypeScript files to JavaScript files.

Discussion

The convert_ts_to_js() function converts one or more TypeScript files (files that end with the .ts extension) to JavaScript syntax. The resulting files are saved with a .js extension using the same name as the filename specified for the TypeScript files.

dim tsFiles as c =<<%files%
C:\aa\example\example.WebProjects\JavaScript.WebProject\typescript\greeter.ts
C:\aa\example\example.WebProjects\JavaScript.WebProject\typescript\students.ts
%files%

dim results as c = ""

results = convert_ts_to_js(tsFiles)
? results
= "[]"

The next example demonstrates a conversion where several errors occurred:

dim tsFiles as c =<<%files%
C:\aa\example\example.WebProjects\JavaScript.WebProject\typescript\greeter_err.ts
C:\aa\example\example.WebProjects\JavaScript.WebProject\typescript\students_err.ts
%files%

dim results as c = ""

results = convert_ts_to_js(tsFiles)
? results
= [
  {
    "filename": "C:/aa/example/example.WebProjects/JavaScript.WebProject/typescript/greeter_err.ts",
    "error": "Duplicate function implementation.",
    "line": 1,
    "column": 10
  },
  {
    "filename": "C:/aa/example/example.WebProjects/JavaScript.WebProject/typescript/greeter_err.ts",
    "error": "Cannot redeclare block-scoped variable 'user'.",
    "line": 5,
    "column": 5
  },
  {
    "filename": "C:/aa/example/example.WebProjects/JavaScript.WebProject/typescript/students_err.ts",
    "error": "Duplicate function implementation.",
    "line": 13,
    "column": 10
  },
  {
    "filename": "C:/aa/example/example.WebProjects/JavaScript.WebProject/typescript/students_err.ts",
    "error": "Cannot redeclare block-scoped variable 'user'.",
    "line": 17,
    "column": 5
  }
]

See Also