Skip to content

Commit

Permalink
Clean up and add comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
jjrv committed Jan 15, 2016
1 parent aaa52f2 commit d71969e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
5 changes: 0 additions & 5 deletions src/schema/ExporterTS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ import * as Promise from 'bluebird';
import {Address, Cache} from 'cget'
import {Namespace} from './Namespace';
import {Type} from './Type';
//import {Scope, TypeMember} from './Scope';
//import {Source} from './Source';
//import {QName} from './QName';
//import * as types from './types';
//import * as schema from '../schema';

/** Export parsed schema to a TypeScript d.ts definition file. */

Expand Down
4 changes: 3 additions & 1 deletion src/schema/Namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,13 @@ export class Namespace {
name: string;
cachePath: string;

/** Invisible document element defining the types of XML file root elements. */
doc: Type;

/** Types of all elements in the document. */
typeList: Type[] = [];
// childList: Member[] = [];

/** List of URL addresses of files with definitions for this namespace. */
sourceList: string[];

exported: boolean;
Expand Down
20 changes: 14 additions & 6 deletions src/schema/Type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ export class Type {
exportContentTS(namespace: Namespace, indent: string) {
var output: string[] = [];

if(this.primitiveList && this.primitiveList.length) {
if(this.primitiveList.length > 1) {
output.push('(' + this.primitiveList.join(' | ') + ')');
} else output.push(this.primitiveList[0]);
if(this.literalType) {
if(this.primitiveList && this.primitiveList.length > 0) {
if(this.primitiveList.length > 1) {
output.push('(' + this.primitiveList.join(' | ') + ')');
} else output.push(this.primitiveList[0]);
} else output.push(this.literalType);
} else {
var members = this.exportMembersTS(namespace, indent + '\t', '');

Expand Down Expand Up @@ -44,7 +46,7 @@ export class Type {

var content = this.exportContentTS(namespace, indent);

if(this.primitiveList && this.primitiveList.length) {
if(this.literalType) {
output.push(indent + syntaxPrefix + 'type ' + this.name + ' = ' + content + ';');
} else {
if(this.parent) parentDef = ' extends ' + this.parent.exportRefTS(namespace, indent + '\t');
Expand Down Expand Up @@ -114,12 +116,18 @@ export class Type {
name: string;
namespace: Namespace;

// aliasable: boolean; // Type can be represented as a type alias in TypeScript if attributeList and childList are empty, and it has no name.
/** JavaScript type name, if the XML type only contains single value
* that can be parsed into a JavaScript value. */
literalType: string;
/** List of allowed literal values, if such a restriction is defined. */
primitiveList: string[];

/** XML attributes in an element of this type. */
attributeList: Member[];
/** Allowed child elements for an element of this type. */
childList: Member[];

/** Parent type this is derived from. */
parent: Type;

comment: string;
Expand Down
3 changes: 1 addition & 2 deletions src/xsd/Exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,8 @@ function exportType(type: types.TypeBase, namespace: schema.Namespace) {
if(primitiveList) primitiveList = primitiveList.map((content: string) => '"' + content + '"');
}

if(!primitiveList) primitiveList = [parentPrimitive.name];

outType.primitiveList = primitiveList;
outType.literalType = parentPrimitive.name;
}

var parent = type.parent;
Expand Down

0 comments on commit d71969e

Please sign in to comment.