Merge pull request #16308 from asgerf/js/model-generation-quote

JS: Fix naming issue in generated models
This commit is contained in:
Rasmus Wriedt Larsen
2024-04-25 11:36:36 +02:00
committed by GitHub
6 changed files with 40 additions and 24 deletions

View File

@@ -108,7 +108,11 @@ module ModelExport<ModelExportSig S> {
}
predicate exposedName(API::Node node, string type, string path) {
node = API::moduleExport(type) and path = ""
exists(string moduleName |
node = API::moduleExport(moduleName) and
path = "" and
type = "(" + moduleName + ")"
)
}
predicate suggestedName(API::Node node, string type) {

View File

@@ -34,6 +34,11 @@ class Location = JS::Location;
*
* Type names have form `package.type` or just `package` if referring to the package export
* object. If `package` contains a `.` character it must be enclosed in single quotes, such as `'package'.type`.
*
* A type name of form `(package)` may also be used when refering to the package export object.
* We allow this syntax as an alternative to the above, so models generated based on `EndpointNaming` look more consistent.
* However, access paths are deliberately not parsed here, as we can not handle aliasing at this stage.
* The model generator must explicitly generate the step between `(package)` and `(package).foo`, for example.
*/
bindingset[rawType]
predicate parseTypeString(string rawType, string package, string qualifiedName) {
@@ -42,6 +47,9 @@ predicate parseTypeString(string rawType, string package, string qualifiedName)
package = rawType.regexpCapture(regexp, 1).regexpReplaceAll("^'|'$", "") and
qualifiedName = rawType.regexpCapture(regexp, 2).regexpReplaceAll("^\\.", "")
)
or
package = rawType.regexpCapture("[(]([^)]+)[)]", 1) and
qualifiedName = ""
}
/**