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

[Unity] 生成的index.d.ts连续出现2个*/导致语法报错,目前仅发现ICSharpCode.SharpZipLib.Zip.Compression.Streams.StreamManipulator #659

Closed
ankisme opened this issue Feb 11, 2022 · 5 comments
Assignees

Comments

@ankisme
Copy link

ankisme commented Feb 11, 2022

error log | 日志或报错信息

这是生成的index.d.ts,报错的地方我标注了,搜//可以找到

declare module 'csharp' {
    import * as CSharp from 'csharp';
    export default CSharp;
}
declare module 'csharp' {
    interface $Ref<T> {
        value: T
    }
    namespace System {
        interface Array$1<T> extends System.Array {
            get_Item(index: number):T;
            set_Item(index: number, value: T):void;
        }
    }
    interface $Task<T> {}
    namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams {
        /**
        * This class allows us to retrieve a specified number of bits from
        * the input buffer, as well as copy big byte blocks.
        * It uses an int buffer to store up to 31 bits for direct
        * manipulation.  This guarantees that we can get at least 16 bits,
        * but we only need at most 15, so this is all safe.
        * There are some optimizations in this class, for example, you must
        * never peek more than 8 bits more than needed, and you must first
        * peek bits before you may drop them.  This is not a general purpose
        * class but optimized for the behaviour of the Inflater.
        * authors of the original java version : John Leuner, Jochen Hoenicke
        */
        class StreamManipulator extends System.Object
        {
        /**
            * Gets the number of bits available in the bit buffer.  This must be
            * only called when a previous PeekBits() returned -1.
            * @returns 
            the number of bits available.
            */
            public get AvailableBits(): number;
            /** Gets the number of bytes available.
            * @returns 
            The number of bytes available.
            */
            public get AvailableBytes(): number;
            /** Returns true when SetInput can be called */
            public get IsNeedingInput(): boolean;
            /**
            * Get the next sequence of bits but don't increase input pointer.  bitCount must be
            * less or equal 16 and if this call succeeds, you must drop
            * at least n - 8 bits in the next call.
            * @param bitCount The number of bits to peek.
            * @returns 
            the value of the bits, or -1 if not enough bits available.  */
            */
            // 上方这行报错了,提示"应为标识符",因为连续出现了2个*/
            public PeekBits ($bitCount: number) : number
            public TryGetBits ($bitCount: number, $output: $Ref<number>, $outputOffset?: number) : boolean
            public TryGetBits ($bitCount: number, $array: $Ref<System.Array$1<number>>, $index: number) : boolean
            /**
            * Drops the next n bits from the input.  You should have called PeekBits
            * with a bigger or equal n before, to make sure that enough bits are in
            * the bit buffer.
            * @param bitCount The number of bits to drop.
            */
            public DropBits ($bitCount: number) : void
            /**
            * Gets the next n bits and increases input pointer.  This is equivalent
            * to
            * followed by
            * , except for correct error handling.
            * @param bitCount The number of bits to retrieve.
            * @returns 
            the value of the bits, or -1 if not enough bits available.
            */
            public GetBits ($bitCount: number) : number
            public SkipToByteBoundary () : void
            /**
            * Copies bytes from input buffer to output buffer starting
            * at output[offset].  You have to make sure, that the buffer is
            * byte aligned.  If not enough bytes are available, copies fewer
            * bytes.
            * @param output 
            The buffer to copy bytes to.
            * @param offset 
            The offset in the buffer at which copying starts
            * @param length 
            The length to copy, 0 is allowed.
            * @returns 
            The number of bytes copied, 0 if no bytes were available.
            */
            public CopyBytes ($output: System.Array$1<number>, $offset: number, $length: number) : number
            public Reset () : void
            /**
            * Add more input for consumption.
            * Only call when IsNeedingInput returns true
            * @param buffer data to be input
            * @param offset offset of first byte of input
            * @param count number of bytes of input to add.
            */
            public SetInput ($buffer: System.Array$1<number>, $offset: number, $count: number) : void
            public constructor ()
        }
    }
    namespace System {
        class Object
        {
        }
        class Int32 extends System.ValueType implements System.IComparable, System.IComparable$1<number>, System.IConvertible, System.IEquatable$1<number>, System.IFormattable
        {
        }
        class ValueType extends System.Object
        {
        }
        interface IComparable
        {
        }
        interface IComparable$1<T>
        {
        }
        interface IConvertible
        {
        }
        interface IEquatable$1<T>
        {
        }
        interface IFormattable
        {
        }
        class Boolean extends System.ValueType implements System.IComparable, System.IComparable$1<boolean>, System.IConvertible, System.IEquatable$1<boolean>
        {
        }
        class Byte extends System.ValueType implements System.IComparable, System.IComparable$1<number>, System.IConvertible, System.IEquatable$1<number>, System.IFormattable
        {
        }
        interface ICloneable
        {
        }
        class Void extends System.ValueType
        {
        }
        class Array extends System.Object implements System.ICloneable, System.Collections.IEnumerable, System.Collections.IList, System.Collections.IStructuralComparable, System.Collections.IStructuralEquatable, System.Collections.ICollection
        {
        }
    }
    namespace System.Collections {
        interface IEnumerable
        {
        }
        interface IList extends System.Collections.IEnumerable, System.Collections.ICollection
        {
        }
        interface ICollection extends System.Collections.IEnumerable
        {
        }
        interface IStructuralComparable
        {
        }
        interface IStructuralEquatable
        {
        }
    }
    namespace System.Collections.Generic {
        interface IList$1<T> extends System.Collections.IEnumerable, System.Collections.Generic.ICollection$1<T>, System.Collections.Generic.IEnumerable$1<T>
        {
        }
        interface ICollection$1<T> extends System.Collections.IEnumerable, System.Collections.Generic.IEnumerable$1<T>
        {
        }
        interface IEnumerable$1<T> extends System.Collections.IEnumerable
        {
        }
        interface IReadOnlyCollection$1<T> extends System.Collections.IEnumerable, System.Collections.Generic.IEnumerable$1<T>
        {
        }
        interface IReadOnlyList$1<T> extends System.Collections.IEnumerable, System.Collections.Generic.IReadOnlyCollection$1<T>, System.Collections.Generic.IEnumerable$1<T>
        {
        }
    }
}

context | 编译/运行环境

Unity 2020.3.26f1c1
Unity_Plugin_1.2.3,Version:15
2022/2/11拉取的最新puerts代码

how to reproduce | 复现步骤

  1. TsConfig.cs如下,点击Generate index.d.ts按钮后,导出的index.d.ts中则连续出现2个*/
using Puerts;
using System;
using System.Collections.Generic;

[Configure]
public class PuertsConfig
{
	[Binding]
	static IEnumerable<Type> DynamicBindings
	{
		get
		{
			return new List<Type>()
			{
				typeof(ICSharpCode.SharpZipLib.Zip.Compression.Streams.StreamManipulator),
			};
		}
	}
}
  1. 第三方文件StreamManipulator.cs文件内容如下
#region 程序集 ICSharpCode.SharpZipLib, Version=1.3.2.10, Culture=neutral, PublicKeyToken=1b03e6acf1164f73
// D:\proj\mine\gopath\src\gitee-client\Assets\Packages\SharpZipLib.1.3.2\lib\net45\ICSharpCode.SharpZipLib.dll
#endregion

namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams
{
	//
	// 摘要:
	//     This class allows us to retrieve a specified number of bits from the input buffer,
	//     as well as copy big byte blocks. It uses an int buffer to store up to 31 bits
	//     for direct manipulation. This guarantees that we can get at least 16 bits, but
	//     we only need at most 15, so this is all safe. There are some optimizations in
	//     this class, for example, you must never peek more than 8 bits more than needed,
	//     and you must first peek bits before you may drop them. This is not a general
	//     purpose class but optimized for the behaviour of the Inflater. authors of the
	//     original java version : John Leuner, Jochen Hoenicke
	public class StreamManipulator
	{
		public StreamManipulator();

		//
		// 摘要:
		//     Gets the number of bits available in the bit buffer. This must be only called
		//     when a previous PeekBits() returned -1.
		//
		// 返回结果:
		//     the number of bits available.
		public int AvailableBits { get; }
		//
		// 摘要:
		//     Gets the number of bytes available.
		//
		// 返回结果:
		//     The number of bytes available.
		public int AvailableBytes { get; }
		//
		// 摘要:
		//     Returns true when SetInput can be called
		public bool IsNeedingInput { get; }

		//
		// 摘要:
		//     Copies bytes from input buffer to output buffer starting at output[offset]. You
		//     have to make sure, that the buffer is byte aligned. If not enough bytes are available,
		//     copies fewer bytes.
		//
		// 参数:
		//   output:
		//     The buffer to copy bytes to.
		//
		//   offset:
		//     The offset in the buffer at which copying starts
		//
		//   length:
		//     The length to copy, 0 is allowed.
		//
		// 返回结果:
		//     The number of bytes copied, 0 if no bytes were available.
		//
		// 异常:
		//   T:System.ArgumentOutOfRangeException:
		//     Length is less than zero
		//
		//   T:System.InvalidOperationException:
		//     Bit buffer isnt byte aligned
		public int CopyBytes(byte[] output, int offset, int length);
		//
		// 摘要:
		//     Drops the next n bits from the input. You should have called PeekBits with a
		//     bigger or equal n before, to make sure that enough bits are in the bit buffer.
		//
		// 参数:
		//   bitCount:
		//     The number of bits to drop.
		public void DropBits(int bitCount);
		//
		// 摘要:
		//     Gets the next n bits and increases input pointer. This is equivalent to ICSharpCode.SharpZipLib.Zip.Compression.Streams.StreamManipulator.PeekBits(System.Int32)
		//     followed by ICSharpCode.SharpZipLib.Zip.Compression.Streams.StreamManipulator.DropBits(System.Int32),
		//     except for correct error handling.
		//
		// 参数:
		//   bitCount:
		//     The number of bits to retrieve.
		//
		// 返回结果:
		//     the value of the bits, or -1 if not enough bits available.
		public int GetBits(int bitCount);
		//
		// 摘要:
		//     Get the next sequence of bits but don't increase input pointer. bitCount must
		//     be less or equal 16 and if this call succeeds, you must drop at least n - 8 bits
		//     in the next call.
		//
		// 参数:
		//   bitCount:
		//     The number of bits to peek.
		//
		// 返回结果:
		//     the value of the bits, or -1 if not enough bits available. */
		public int PeekBits(int bitCount);
		//
		// 摘要:
		//     Resets state and empties internal buffers
		public void Reset();
		//
		// 摘要:
		//     Add more input for consumption. Only call when IsNeedingInput returns true
		//
		// 参数:
		//   buffer:
		//     data to be input
		//
		//   offset:
		//     offset of first byte of input
		//
		//   count:
		//     number of bytes of input to add.
		public void SetInput(byte[] buffer, int offset, int count);
		//
		// 摘要:
		//     Skips to the next byte boundary.
		public void SkipToByteBoundary();
		//
		// 摘要:
		//     Tries to grab the next bitCount bits from the input and sets output to the value,
		//     adding outputOffset.
		//
		// 返回结果:
		//     true if enough bits could be read, otherwise false
		public bool TryGetBits(int bitCount, ref int output, int outputOffset = 0);
		//
		// 摘要:
		//     Tries to grab the next bitCount bits from the input and sets index of array to
		//     the value.
		//
		// 返回结果:
		//     true if enough bits could be read, otherwise false
		public bool TryGetBits(int bitCount, ref byte[] array, int index);
	}
}

more | 其他

@zombieyang zombieyang self-assigned this Feb 13, 2022
@zombieyang
Copy link
Contributor

image

这个库的注释文字里本身就带有`*/`,我也很无奈

@ankisme
Copy link
Author

ankisme commented Feb 14, 2022

QQ截图20220214144134

这个注释是比较奇特没错,要不要考虑统一把这种注释replace掉呢?我本地是这么处理的,由于pull request我还不知道怎么提交,所以提个issue看方不方便统一处理一下

@chexiongsheng
Copy link
Collaborator

image

这个库的注释文字里本身就带有*/,我也很无奈

看能不能replace或者escape掉

@zombieyang
Copy link
Contributor

提交了一个修复办法 8932317
因为我现在在疫区没有能复现的机器,有时间麻烦帮忙验证下

@ankisme
Copy link
Author

ankisme commented Feb 15, 2022

提交了一个修复办法 8932317 因为我现在在疫区没有能复现的机器,有时间麻烦帮忙验证下

测试了下,是正常的,这是生成的index.d.ts

   
declare module 'csharp' {
    import * as CSharp from 'csharp';
    export default CSharp;
}
declare module 'csharp' {
    interface $Ref<T> {
        value: T
    }
    namespace System {
        interface Array$1<T> extends System.Array {
            get_Item(index: number):T;
            set_Item(index: number, value: T):void;
        }
    }
    interface $Task<T> {}
    namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams {
        /**
        * This class allows us to retrieve a specified number of bits from
        * the input buffer, as well as copy big byte blocks.
        * It uses an int buffer to store up to 31 bits for direct
        * manipulation.  This guarantees that we can get at least 16 bits,
        * but we only need at most 15, so this is all safe.
        * There are some optimizations in this class, for example, you must
        * never peek more than 8 bits more than needed, and you must first
        * peek bits before you may drop them.  This is not a general purpose
        * class but optimized for the behaviour of the Inflater.
        * authors of the original java version : John Leuner, Jochen Hoenicke
        */
        class StreamManipulator extends System.Object
        {
        /**
            * Gets the number of bits available in the bit buffer.  This must be
            * only called when a previous PeekBits() returned -1.
            * @returns 
            the number of bits available.
            */
            public get AvailableBits(): number;
            /** Gets the number of bytes available.
            * @returns 
            The number of bytes available.
            */
            public get AvailableBytes(): number;
            /** Returns true when SetInput can be called */
            public get IsNeedingInput(): boolean;
            /**
            * Get the next sequence of bits but don't increase input pointer.  bitCount must be
            * less or equal 16 and if this call succeeds, you must drop
            * at least n - 8 bits in the next call.
            * @param bitCount The number of bits to peek.
            * @returns 
            the value of the bits, or -1 if not enough bits available.  * /
            */
            public PeekBits ($bitCount: number) : number
            public TryGetBits ($bitCount: number, $output: $Ref<number>, $outputOffset?: number) : boolean
            public TryGetBits ($bitCount: number, $array: $Ref<System.Array$1<number>>, $index: number) : boolean
            /**
            * Drops the next n bits from the input.  You should have called PeekBits
            * with a bigger or equal n before, to make sure that enough bits are in
            * the bit buffer.
            * @param bitCount The number of bits to drop.
            */
            public DropBits ($bitCount: number) : void
            /**
            * Gets the next n bits and increases input pointer.  This is equivalent
            * to
            * followed by
            * , except for correct error handling.
            * @param bitCount The number of bits to retrieve.
            * @returns 
            the value of the bits, or -1 if not enough bits available.
            */
            public GetBits ($bitCount: number) : number
            public SkipToByteBoundary () : void
            /**
            * Copies bytes from input buffer to output buffer starting
            * at output[offset].  You have to make sure, that the buffer is
            * byte aligned.  If not enough bytes are available, copies fewer
            * bytes.
            * @param output 
            The buffer to copy bytes to.
            * @param offset 
            The offset in the buffer at which copying starts
            * @param length 
            The length to copy, 0 is allowed.
            * @returns 
            The number of bytes copied, 0 if no bytes were available.
            */
            public CopyBytes ($output: System.Array$1<number>, $offset: number, $length: number) : number
            public Reset () : void
            /**
            * Add more input for consumption.
            * Only call when IsNeedingInput returns true
            * @param buffer data to be input
            * @param offset offset of first byte of input
            * @param count number of bytes of input to add.
            */
            public SetInput ($buffer: System.Array$1<number>, $offset: number, $count: number) : void
            public constructor ()
        }
    }
    namespace System {
        class Object
        {
        }
        class Int32 extends System.ValueType implements System.IComparable, System.IComparable$1<number>, System.IConvertible, System.IEquatable$1<number>, System.IFormattable
        {
        }
        class ValueType extends System.Object
        {
        }
        interface IComparable
        {
        }
        interface IComparable$1<T>
        {
        }
        interface IConvertible
        {
        }
        interface IEquatable$1<T>
        {
        }
        interface IFormattable
        {
        }
        class Boolean extends System.ValueType implements System.IComparable, System.IComparable$1<boolean>, System.IConvertible, System.IEquatable$1<boolean>
        {
        }
        class Byte extends System.ValueType implements System.IComparable, System.IComparable$1<number>, System.IConvertible, System.IEquatable$1<number>, System.IFormattable
        {
        }
        interface ICloneable
        {
        }
        class Void extends System.ValueType
        {
        }
        class Array extends System.Object implements System.ICloneable, System.Collections.IEnumerable, System.Collections.IList, System.Collections.IStructuralComparable, System.Collections.IStructuralEquatable, System.Collections.ICollection
        {
        }
    }
    namespace System.Collections {
        interface IEnumerable
        {
        }
        interface IList extends System.Collections.IEnumerable, System.Collections.ICollection
        {
        }
        interface ICollection extends System.Collections.IEnumerable
        {
        }
        interface IStructuralComparable
        {
        }
        interface IStructuralEquatable
        {
        }
    }
    namespace System.Collections.Generic {
        interface IList$1<T> extends System.Collections.IEnumerable, System.Collections.Generic.ICollection$1<T>, System.Collections.Generic.IEnumerable$1<T>
        {
        }
        interface ICollection$1<T> extends System.Collections.IEnumerable, System.Collections.Generic.IEnumerable$1<T>
        {
        }
        interface IEnumerable$1<T> extends System.Collections.IEnumerable
        {
        }
        interface IReadOnlyCollection$1<T> extends System.Collections.IEnumerable, System.Collections.Generic.IEnumerable$1<T>
        {
        }
        interface IReadOnlyList$1<T> extends System.Collections.IEnumerable, System.Collections.Generic.IReadOnlyCollection$1<T>, System.Collections.Generic.IEnumerable$1<T>
        {
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants