How Google Script Is Converted To Javascript
GS files, specifically Google Apps Script (GAS) files, are server-side JavaScript files with a .gs extension. When deployed or executed, GAS files are converted to JavaScript (JS) for processing. Here's a breakdown of the conversion process:
- Removal of GAS-specific syntax: The GAS file's syntax, which includes features like
@grantandPropertiesService, is stripped away, leaving standard JavaScript code. - ES6+ compatibility: GAS uses a subset of ECMAScript 6 (ES6) features, but not all of them. The conversion process ensures that the code is compatible with modern JavaScript engines, using features like destructuring and async/await.
- No renaming of files: As mentioned in Issue #51 of the Google CLASP project, there is no automatic renaming of
.gsfiles to.jsbefore deployment or execution. The file extension remains.gsfor server-side GAS files. - JS code generation: The converted JavaScript code is generated based on the GAS file's content, using the same logic and semantics as standard JavaScript. This includes variable declarations, function definitions, and control flow statements.
In summary, the conversion of GS to JS involves:
Stripping away GAS-specific syntax
Ensuring ES6+ compatibility
No automatic renaming of file extensions
Generation of standard JavaScript code
This conversion process allows GAS files to be executed on the server-side, leveraging the power of JavaScript while maintaining compatibility with modern JavaScript engines.