Skip to content

Commit

Permalink
Merge pull request #47 from georgejecook/fix/overridden-namespace-nam…
Browse files Browse the repository at this point in the history
…e-checking

fix(validation): correctly handles sitatuions where namespaces are in…
  • Loading branch information
georgejecook authored May 8, 2022
2 parents a9d2bd9 + 1b5d491 commit 19c6acf
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 110 deletions.
128 changes: 22 additions & 106 deletions scripts/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,101 +559,38 @@ let maestroSample = {
'retainStagingFolder': true
};

// let nba = {
// 'rootDir': '/home/george/hope/nba/nba-roku/src',
// 'stagingFolderPath': 'build',
// 'plugins': [
// '/home/george/hope/open-source/maestro/maestro-roku-bsc-plugin/dist/plugin.js',
// '/home/george/hope/open-source/rooibos/bsc-plugin/dist/plugin.js'
// ],
// 'files': [
// 'manifest',
// 'source/**/*.*',
// 'images/**/*.*',
// 'sounds/**/*.*',
// 'sounds/*.*',
// 'fonts/**/*.*',
// 'meta/**/*.*',
// 'components/**/*.*',
// { 'src': '../src-dev/source/**/*.*', 'dest': 'source' }
// ],
// 'autoImportComponentScript': true,
// 'createPackage': false,
// 'diagnosticFilters': [
// {
// 'src': '**/roku_modules/**/*.*'
// },
// {
// 'src': '**/RALETrackerTask.*'
// },
// {
// 'src': '**/*spec.bs',
// 'codes': ['LINT3011']
// },
// {
// 'src': '**/bitmovinAnalytics/**/*.*'
// },
// {
// 'src': '**/bitmovinPlayer/**/*.*'
// },
// {
// 'src': '**/mediakind/**/*.*'
// }
// ],
// 'maestro': {
// 'excludeFilters': [
// '**/roku_modules/**/*',
// '**/roku_modules/**/*',
// '**/rooibos/**/*',
// '**/bitmovinAnalytics/**/*.*',
// '**/bitmovinPlayer/**/*.*',
// '**/mediakind/**/*.*',
// '**/NewRelicAgent/**/*.*',
// '**/NewRelicAgent.brs'
// ],
// 'buildForIDE': false,
// 'extraValidation': {
// 'doExtraValidation': true,
// 'doExtraImportValidation': true
// }
// },
// 'rooibos': {
// 'isRecordingCodeCoverage': false,
// 'testsFilePattern': null
// },
// 'rokuLog': {
// 'strip': false,
// 'insertPkgPath': true,
// 'removeComments': true
// },
// 'logLevel': 'error',
// 'retainStagingFolder': true
// };


let nbaLatest = {
'rootDir': '/home/george/hope/nba/nba-roku/src',
let robot = {
'stagingFolderPath': 'build',
'rootDir': '/home/george/hope/tw/roku-robot/src',
'extends': '/home/george/hope/tw/roku-robot/bsconfig.json',
'files': [
'!**/*.i8n.json',
'manifest',
'source/**/*.*',
'images/**/*.*',
'sounds/**/*.*',
'sounds/*.*',
'fonts/**/*.*',
'meta/**/*.*',
'components/**/*.*',
{ 'src': '../src-dev/source/**/*.*', 'dest': 'source' }
'meta/**/*.*',
{ 'src': '../src-dev/meta/**/*.*', 'dest': 'meta' },
{ 'src': '../src-dev/source/**/*.*', 'dest': 'source' },
{ 'src': '../src-dev/images/**/*.*', 'dest': 'images' },
'!**/*.spec.bs'
],
'plugins': [
'/home/george/hope/open-source/maestro/maestro-roku-bsc-plugin/dist/plugin.js',
'/home/george/hope/open-source/rooibos/bsc-plugin/dist/plugin.js'
],
'autoImportComponentScript': true,
'createPackage': false,
'diagnosticFilters': [
{
'src': '**/roku_modules/**/*.*'
},
{
'src': '**/rooibos/**/*.*'
'src': 'node_modules/**/*.*'
},
{
'src': '**/maestro/**/*.*'
},
{
'src': '**/RALETrackerTask.*'
Expand All @@ -662,37 +599,14 @@ let nbaLatest = {
'src': '**/*spec.bs',
'codes': ['LINT3011']
},
{
'src': '**/bitmovinAnalytics/**/*.*'
},
{
'src': '**/bitmovinPlayer/**/*.*'
},
{
'src': '**/mediakind/**/*.*'
},
{
'src': '**/NewRelicAgent/**/*.*'
},
{
'src': '**/NewRelicAgent.brs'
}
],
'plugins': [
'/home/george/hope/open-source/maestro/maestro-roku-bsc-plugin/dist/plugin.js',
'/home/george/hope/open-source/maestro/roku-log-bsc-plugin/dist/plugin.js',
'/home/george/hope/open-source/rooibos/bsc-plugin/dist/plugin.js'
1128
],
'maestro': {
'excludeFilters': [
'**/RALETrackerTask.*',
'**/roku_modules/**/*',
'**/node_modules/**/*',
'**/rooibos/**/*',
'**/bitmovinAnalytics/**/*.*',
'**/bitmovinPlayer/**/*.*',
'**/mediakind/**/*.*',
'**/NewRelicAgent/**/*.*',
'**/NewRelicAgent.brs'
'**/rooibos/**/*'
],
'buildForIDE': false,
'extraValidation': {
Expand All @@ -717,10 +631,12 @@ let nbaLatest = {
}
};


let programBuilder = new ProgramBuilder();
programBuilder.run(
// swv
zapp
// zapp
robot
// maestro
// corco
// nbaLatest
Expand Down
20 changes: 18 additions & 2 deletions src/lib/files/ProjectFileMap.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { BrsFile, BscFile, ClassStatement, XmlFile } from 'brighterscript';
import { ParseMode } from 'brighterscript';
import type { BrsFile, BscFile, ClassStatement, NamespaceStatement, XmlFile } from 'brighterscript';
import { ParseMode, isBrsFile } from 'brighterscript';

import { File } from './File';
import { FileType } from './FileType';
Expand All @@ -22,6 +22,7 @@ export class ProjectFileMap {
public allFiles: Map<string, File>;
public nodeClasses = new Map<string, NodeClass>();
public nodeClassesByPath = new Map<string, NodeClass[]>();
public pathsByNamespace: Record<string, Record<string, boolean>> = {};

get XMLComponentNames(): string[] {
return [...this.allXMLComponentFiles.keys()];
Expand Down Expand Up @@ -115,6 +116,18 @@ export class ProjectFileMap {
this.allClasses.set(className, classStatement);
mFile.classNames.add(className);
}
public addNamespaces(file: BrsFile) {

for (let ns of file.parser.references.namespaceStatements) {
let nsName = ns.getName(ParseMode.BrighterScript).toLowerCase();
let paths = this.pathsByNamespace[nsName];
if (!paths) {
paths = {};
}
paths[file.pkgPath.toLowerCase().replace('.d.bs', '.bs')] = true;
this.pathsByNamespace[nsName] = paths;
}
}

public removeClass(name: string) {
this.allClassNames.delete(name);
Expand Down Expand Up @@ -143,6 +156,9 @@ export class ProjectFileMap {

public addFile(file: File) {
this.removeFile(file);
if (isBrsFile(file.bscFile)) {
this.addNamespaces(file.bscFile);
}
this.allFiles.set(file.fullPath, file);
}

Expand Down
4 changes: 2 additions & 2 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1097,9 +1097,9 @@ export class MaestroPlugin implements CompilerPlugin {
return false;
}
private isNamespaceImported(ns: NamespaceContainer, importedPkgPaths: string[]) {
let p = ns.file.pkgPath.toLowerCase().replace('.d.bs', '.bs');
let nsPathLookup = this.fileMap.pathsByNamespace[ns.fullName.toLowerCase()];
for (let s of importedPkgPaths) {
if (p === s) {
if (nsPathLookup?.[s]) {
return true;
}
}
Expand Down

0 comments on commit 19c6acf

Please sign in to comment.