Skip to content
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

Rework exports to allow using classes in type hints #684

Merged
merged 3 commits into from
Nov 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
},
"devDependencies": {
"@rollup/plugin-commonjs": "^21.0.1",
"@types/css-font-loading-module": "0.0.7",
"@types/jasmine": "^3.10.2",
"@types/resize-observer-browser": "^0.1.6",
"concurrently": "^6.3.0",
Expand Down
33 changes: 18 additions & 15 deletions rollup.resolve.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const join = require('path').join;
const path = require('path');
const glob = require('glob').sync;
const fs = require('fs');

Expand All @@ -14,22 +14,29 @@ module.exports = function (options) {

const extension = types ? '.d.ts' : '.js';

if (importee.startsWith('**')) {
if (fs.existsSync(importee)) {
return importee;
} else if (importee.startsWith('**')) {
return importee;
} else {
const importerDir = path.dirname(importer);
let resolved = importee;

const match = Object.entries(mappings).filter(m => importee.startsWith(m[0]));
if (!match || match.length === 0) {
return null;
if (match && match.length > 0) {
if (match[0][1].endsWith(extension)) {
resolved = path.join(process.cwd(), match[0][1]);
} else {
resolved = path.join(process.cwd(), match[0][1], importee.substring(match[0][0].length));
}
} else {
resolved = path.join(importerDir, importee);
}

if (match[0][1].endsWith(extension)) {
return join(process.cwd(), match[0][1]);
if (fs.existsSync(path.join(resolved, 'index' + extension))) {
resolved = path.join(resolved, 'index');
}

let resolved = join(process.cwd(), match[0][1], importee.substring(match[0][0].length));
if (fs.existsSync(join(resolved, 'index' + extension))) {
return join(resolved, 'index' + extension);
}
return resolved + extension;
}
},
Expand All @@ -39,11 +46,7 @@ module.exports = function (options) {
cwd: process.cwd()
});
const source = files
.map(
(file, i) =>
`import _${i} from ${JSON.stringify(join(process.cwd(), file))};
export { _${i} };`
)
.map((file, i) => `export * as _${i} from ${JSON.stringify(path.join(process.cwd(), file))};`)
.join('\r\n');
return source;
}
Expand Down
48 changes: 31 additions & 17 deletions src.compiler/csharp/CSharpAstTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ export default class CSharpAstTransformer {
protected _testMethodAttribute: string = 'microsoft.visualStudio.testTools.unitTesting.TestMethod';

public get extension(): string {
return '.cs'
return '.cs';
}


public constructor(typeScript: ts.SourceFile, context: CSharpEmitterContext) {
this._typeScriptFile = typeScript;
this._context = context;
Expand Down Expand Up @@ -143,11 +142,27 @@ export default class CSharpAstTransformer {
globalExports.forEach(x => {
if (!x.name && x.exportClause) {
if (ts.isNamespaceExport(x.exportClause)) {
this._context.addTsNodeDiagnostics(
x.exportClause,
'Namespace exports are not yet supported',
ts.DiagnosticCategory.Error
);
if (!x.moduleSpecifier) {
this._context.addTsNodeDiagnostics(
x.exportClause,
'Failed to export namespace, missing module specifier',
ts.DiagnosticCategory.Error
);
} else {
const module = this._context.typeChecker.getSymbolAtLocation(x.moduleSpecifier);
if (!module) {
this._context.addTsNodeDiagnostics(
x.exportClause,
'Failed to export namespace, cannot resolve module',
ts.DiagnosticCategory.Error
);
} else {
const exports = this._context.typeChecker.getExportsOfModule(module);
for (const exp of exports) {
this._context.registerSymbolAsExported(exp);
}
}
}
} else {
x.exportClause.elements.forEach(e => {
const symbol = this._context.typeChecker.getTypeAtLocation(e.name)?.symbol;
Expand Down Expand Up @@ -1853,10 +1868,10 @@ export default class CSharpAstTransformer {
this._context.registerSymbol(csMethod);
}
protected mapVisibility(node: ts.Node): cs.Visibility {
if(this._context.isInternal(node)) {
if (this._context.isInternal(node)) {
return cs.Visibility.Internal;
}

if (node.modifiers) {
for (const m of node.modifiers) {
switch (m.kind) {
Expand Down Expand Up @@ -1931,10 +1946,13 @@ export default class CSharpAstTransformer {
block.statements.length > 0 &&
cs.isExpressionStatement(block.statements[0]) &&
cs.isInvocationExpression((block.statements[0] as cs.ExpressionStatement).expression) &&
cs.isBaseLiteralExpression(((block.statements[0] as cs.ExpressionStatement).expression as cs.InvocationExpression).expression)
cs.isBaseLiteralExpression(
((block.statements[0] as cs.ExpressionStatement).expression as cs.InvocationExpression).expression
)
) {
csConstructor.baseConstructorArguments = ((block.statements[0] as cs.ExpressionStatement)
.expression as cs.InvocationExpression).arguments;
csConstructor.baseConstructorArguments = (
(block.statements[0] as cs.ExpressionStatement).expression as cs.InvocationExpression
).arguments;
block.statements.shift();
}
}
Expand Down Expand Up @@ -2098,11 +2116,7 @@ export default class CSharpAstTransformer {
}

protected visitThisExpression(parent: cs.Node, expression: ts.ThisExpression) {
if (
cs.isMemberAccessExpression(parent) &&
parent.tsSymbol &&
this._context.isStaticSymbol(parent.tsSymbol)
) {
if (cs.isMemberAccessExpression(parent) && parent.tsSymbol && this._context.isStaticSymbol(parent.tsSymbol)) {
const identifier = {
parent: parent,
tsNode: expression,
Expand Down
6 changes: 3 additions & 3 deletions src/AlphaTabApiBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ import { Settings } from '@src/Settings';
import { Logger } from '@src/Logger';
import { ModelUtils } from '@src/model/ModelUtils';
import { AlphaTabError, AlphaTabErrorType } from '@src/AlphaTabError';
import { Note } from './model/Note';
import { MidiEventType } from './midi/MidiEvent';
import { MidiEventsPlayedEventArgs } from './synth/MidiEventsPlayedEventArgs';
import { Note } from '@src/model/Note';
import { MidiEventType } from '@src/midi/MidiEvent';
import { MidiEventsPlayedEventArgs } from '@src/synth/MidiEventsPlayedEventArgs';

class SelectionInfo {
public beat: Beat;
Expand Down
12 changes: 6 additions & 6 deletions src/Environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ import { ScoreRenderer } from '@src/rendering/ScoreRenderer';
import { TabBarRendererFactory } from '@src/rendering/TabBarRendererFactory';
import { FontLoadingChecker } from '@src/util/FontLoadingChecker';
import { Logger } from '@src/Logger';
import { LeftHandTapEffectInfo } from './rendering/effects/LeftHandTapEffectInfo';
import { CapellaImporter } from './importer/CapellaImporter';
import { ResizeObserverPolyfill } from './platform/javascript/ResizeObserverPolyfill';
import { WebPlatform } from './platform/javascript/WebPlatform';
import { IntersectionObserverPolyfill } from './platform/javascript/IntersectionObserverPolyfill';
import { AlphaSynthWebWorklet } from './platform/javascript/AlphaSynthAudioWorkletOutput';
import { LeftHandTapEffectInfo } from '@src/rendering/effects/LeftHandTapEffectInfo';
import { CapellaImporter } from '@src/importer/CapellaImporter';
import { ResizeObserverPolyfill } from '@src/platform/javascript/ResizeObserverPolyfill';
import { WebPlatform } from '@src/platform/javascript/WebPlatform';
import { IntersectionObserverPolyfill } from '@src/platform/javascript/IntersectionObserverPolyfill';
import { AlphaSynthWebWorklet } from '@src/platform/javascript/AlphaSynthAudioWorkletOutput';

export class LayoutEngineFactory {
public readonly vertical: boolean;
Expand Down
Loading