import { CSharp } from "./CSharp" ; import { Java } from "./Java" ; import { JavaScript } from "./JavaScript" ; import { Language } from "./Language" ; import { Python } from "./Python" ; import { Ruby } from "./Ruby" ; import { TypeScript } from "./TypeScript" ; /**
 * Lookup of standard languages.
 */ export class LanguagesBag { /**
     * Built-in languages.
     */ private static languages : Language [ ] = [ new CSharp ( ) , new Java ( ) , new JavaScript ( ) , new Python ( ) , new Ruby ( ) , new TypeScript ( ) ] ; /**
     * Known languages, keyed by extension.
     */ private languagesByExtension : { [ i ] : Language ; } = { } ; /**
     * Known languages, keyed by name.
     */ private languagesByName : { [ i ] : Language ; } = { } ; /**
     * Initializes a new instance of the LanguagesBag class.
     */ public constructor ( ) { for ( const language of LanguagesBag . languages ) { this . addLanguage ( language ) ; } } param language public addLanguage ( language ) { this . languagesByExtension [ language . general . extension ] = language ; this . languagesByName [ language . general . name ] = language ; } param extension returns public getLanguageByExtension ( extension ) { if ( ! { } . hasOwnProperty . call ( this . languagesByExtension , extension ) ) { throw new Error ( `Unknown language extension: '${ extension }'.'` ) ; } return this . languagesByExtension [ extension ] ; } param name returns public getLanguageByName ( name ) { if ( ! { } . hasOwnProperty . call ( this . languagesByName , name ) ) { throw new Error ( `Unknown language name: '${ name }'.'` ) ; } return this . languagesByName [ name ] ; } returns public getLanguageNames ( ) { return Object . keys ( this . languagesByName ) ; } }